Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_activesync/kolab_activesync_ui.php
Show All 21 Lines | |||||
* You should have received a copy of the GNU Affero General Public License | * You should have received a copy of the GNU Affero General Public License | ||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
class kolab_activesync_ui | class kolab_activesync_ui | ||||
{ | { | ||||
private $rc; | private $rc; | ||||
private $plugin; | private $plugin; | ||||
private $force_subscriptions = array(); | |||||
public $device = array(); | public $device = array(); | ||||
const SETUP_URL = 'https://kb.kolabenterprise.com/documentation/setting-up-an-activesync-client'; | const SETUP_URL = 'https://kb.kolabenterprise.com/documentation/setting-up-an-activesync-client'; | ||||
public function __construct($plugin) | public function __construct($plugin) | ||||
{ | { | ||||
$this->plugin = $plugin; | $this->plugin = $plugin; | ||||
$this->rc = rcube::get_instance(); | $this->rc = rcube::get_instance(); | ||||
$skin_path = $this->plugin->local_skin_path() . '/'; | $skin_path = $this->plugin->local_skin_path() . '/'; | ||||
$this->skin_path = 'plugins/kolab_activesync/' . $skin_path; | $this->skin_path = 'plugins/kolab_activesync/' . $skin_path; | ||||
$this->plugin->load_config(); | |||||
$this->force_subscriptions = $this->rc->config->get('activesync_force_subscriptions', array()); | |||||
$this->plugin->include_stylesheet($skin_path . 'config.css'); | $this->plugin->include_stylesheet($skin_path . 'config.css'); | ||||
} | } | ||||
public function device_list($attrib = array()) | public function device_list($attrib = array()) | ||||
{ | { | ||||
$attrib += array('id' => 'devices-list'); | $attrib += array('id' => 'devices-list'); | ||||
$devices = $this->plugin->list_devices(); | $devices = $this->plugin->list_devices(); | ||||
Show All 39 Lines | public function device_config_form($attrib = array()) | ||||
if ($attrib['form']) { | if ($attrib['form']) { | ||||
$this->rc->output->add_gui_object('editform', $attrib['form']); | $this->rc->output->add_gui_object('editform', $attrib['form']); | ||||
} | } | ||||
return $table->show($attrib); | return $table->show($attrib); | ||||
} | } | ||||
private function is_protected($folder, $devicetype) | |||||
{ | |||||
$devicetype = strtolower($devicetype); | |||||
if (array_key_exists($devicetype, $this->force_subscriptions)) { | |||||
machniak: `key_exists` is an alias for `array_key_exists` and I prefer to not use aliases. | |||||
return array_key_exists($folder, $this->force_subscriptions[$devicetype]); | |||||
} | |||||
return false; | |||||
} | |||||
public function folder_subscriptions($attrib = array()) | public function folder_subscriptions($attrib = array()) | ||||
{ | { | ||||
if (!$attrib['id']) { | if (!$attrib['id']) { | ||||
$attrib['id'] = 'foldersubscriptions'; | $attrib['id'] = 'foldersubscriptions'; | ||||
} | } | ||||
// group folders by type (show only known types) | // group folders by type (show only known types) | ||||
$folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array(), 'note' => array()); | $folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array(), 'note' => array()); | ||||
$folder_types = kolab_storage::folders_typedata(); | $folder_types = kolab_storage::folders_typedata(); | ||||
$use_fieldsets = rcube_utils::get_boolean($attrib['use-fieldsets']); | $use_fieldsets = rcube_utils::get_boolean($attrib['use-fieldsets']); | ||||
$imei = $this->device['_id']; | $imei = $this->device['_id']; | ||||
$subscribed = array(); | $subscribed = array(); | ||||
if ($imei) { | if ($imei) { | ||||
$folder_meta = $this->plugin->folder_meta(); | $folder_meta = $this->plugin->folder_meta(); | ||||
} | } | ||||
$devicetype = strtolower($this->device['TYPE']); | |||||
$device_force_subscriptions = $this->force_subscriptions[$devicetype]; | |||||
foreach ($this->plugin->list_folders() as $folder) { | foreach ($this->plugin->list_folders() as $folder) { | ||||
if ($folder_types[$folder]) { | if ($folder_types[$folder]) { | ||||
list($type, ) = explode('.', $folder_types[$folder]); | list($type, ) = explode('.', $folder_types[$folder]); | ||||
} | } | ||||
else { | else { | ||||
$type = 'mail'; | $type = 'mail'; | ||||
} | } | ||||
if (is_array($folder_groups[$type])) { | if (is_array($folder_groups[$type])) { | ||||
$folder_groups[$type][] = $folder; | $folder_groups[$type][] = $folder; | ||||
if (!empty($folder_meta) && ($meta = $folder_meta[$folder]) | if ($device_force_subscriptions && array_key_exists($folder, $device_force_subscriptions)) { | ||||
$subscribed[$folder] = intval($device_force_subscriptions[$folder]); | |||||
} else if (!empty($folder_meta) && ($meta = $folder_meta[$folder]) | |||||
&& $meta['FOLDER'] && $meta['FOLDER'][$imei]['S'] | && $meta['FOLDER'] && $meta['FOLDER'][$imei]['S'] | ||||
) { | ) { | ||||
$subscribed[$folder] = intval($meta['FOLDER'][$imei]['S']); | $subscribed[$folder] = intval($meta['FOLDER'][$imei]['S']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// build block for every folder type | // build block for every folder type | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public function folder_subscriptions_block($a_folders, $attrib, $subscribed) | ||||
if ($folder_class = $this->rc->folder_classname($folder)) { | if ($folder_class = $this->rc->folder_classname($folder)) { | ||||
if ($this->rc->text_exists($folder_class)) { | if ($this->rc->text_exists($folder_class)) { | ||||
$foldername = html::quote($this->rc->gettext($folder_class)); | $foldername = html::quote($this->rc->gettext($folder_class)); | ||||
} | } | ||||
$classes[] = $folder_class; | $classes[] = $folder_class; | ||||
} | } | ||||
$table->add_row(); | $table->add_row(); | ||||
$disabled = $this->is_protected($folder, $this->device['TYPE']); | |||||
$table->add('subscription checkbox-cell', $checkbox_sync->show( | $table->add('subscription checkbox-cell', $checkbox_sync->show( | ||||
!empty($subscribed[$folder]) ? $folder : null, | !empty($subscribed[$folder]) ? $folder : null, | ||||
array('value' => $folder, 'id' => $folder_id))); | array('value' => $folder, 'id' => $folder_id, 'disabled' => $disabled))); | ||||
Done Inline ActionsYou could just set disabled=null for when it's not true, and make the whole code shorter. No need for array_merge() and $extra_attributes. And checkboxes could be created out of the loop as before. machniak: You could just set `disabled=null` for when it's not `true`, and make the whole code shorter. | |||||
if ($alarms) { | if ($alarms) { | ||||
$table->add('alarm checkbox-cell', $checkbox_alarm->show( | $table->add('alarm checkbox-cell', $checkbox_alarm->show( | ||||
intval($subscribed[$folder]) > 1 ? $folder : null, | intval($subscribed[$folder]) > 1 ? $folder : null, | ||||
array('value' => $folder, 'id' => $folder_id.'_alarm'))); | array('value' => $folder, 'id' => $folder_id.'_alarm', 'disabled' => $disabled))); | ||||
} | } | ||||
$table->add(join(' ', $classes), html::label($folder_id, $foldername)); | $table->add(join(' ', $classes), html::label($folder_id, $foldername)); | ||||
} | } | ||||
return $table->show(); | return $table->show(); | ||||
} | } | ||||
Show All 24 Lines | public function folder_options_table($folder_name, $devices, $type) | ||||
$_name = trim($info['friendlyname'] . ' ' . $info['os']); | $_name = trim($info['friendlyname'] . ' ' . $info['os']); | ||||
$title = $info['useragent']; | $title = $info['useragent']; | ||||
if ($_name) { | if ($_name) { | ||||
$name .= " ($_name)"; | $name .= " ($_name)"; | ||||
} | } | ||||
} | } | ||||
$disabled = $this->is_protected($folder_name, $device['TYPE']); | |||||
$table->add_row(); | $table->add_row(); | ||||
$table->add(array('class' => 'device', 'title' => $title), $name); | $table->add(array('class' => 'device', 'title' => $title), $name); | ||||
$table->add('subscription checkbox-cell', $checkbox->show(!empty($folder_data[$id]['S']) ? 1 : 0)); | $table->add('subscription checkbox-cell', $checkbox->show(!empty($folder_data[$id]['S']) ? 1 : 0, array('disabled' => $disabled))); | ||||
if ($alarms) { | if ($alarms) { | ||||
$checkbox_alarm = new html_checkbox(array('name' => "_alarms[$id]", 'value' => 1, | $checkbox_alarm = new html_checkbox(array('name' => "_alarms[$id]", 'value' => 1, | ||||
'onchange' => 'return activesync_object.update_sync_data(this)')); | 'onchange' => 'return activesync_object.update_sync_data(this)')); | ||||
$table->add('alarm checkbox-cell', $checkbox_alarm->show($folder_data[$id]['S'] > 1 ? 1 : 0)); | $table->add('alarm checkbox-cell', $checkbox_alarm->show($folder_data[$id]['S'] > 1 ? 1 : 0, array('disabled' => $disabled))); | ||||
} | } | ||||
} | } | ||||
return $table->show(); | return $table->show(); | ||||
} | } | ||||
/** | /** | ||||
* Displays initial page (when no devices are registered) | * Displays initial page (when no devices are registered) | ||||
Show All 24 Lines |
key_exists is an alias for array_key_exists and I prefer to not use aliases.