'type' => 'special'
);
-// Message flags
+// Message flags - system defaults
+// This entry should normally never be changed. It provides the base flags
+// for all users. Flags specific to a certain user should be defined in
+// 'msgflags_user'.
$_prefs['msgflags'] = array(
// Format:
// KEY: Flag name
'type' => 'implicit'
);
+// Message flags - user specific
+// This array contains the list of flags created by the user through the
+// flags UI. Additionally, an admin can define default non-system flags
+// for a user in this preference.
+// See the 'msgflags' preference for the format of this value.
+$_prefs['msgflags_user'] = array(
+ // 'value' = json_encode(array())
+ 'value' => '[]',
+ 'locked' => false,
+ 'shared' => false,
+ 'type' => 'implicit'
+);
+
// The default color to use for flags that don't require row highlighting.
$_prefs['msgflags_color'] = array(
'value' => '#ffffff',
protected $_flags = null;
/**
+ * The 'msgflags_user' preference value.
+ *
+ * @var array
+ */
+ protected $_userflags = null;
+
+ /**
* Save the flag list to the prefs backend.
+ *
+ * @param boolean $user If true, update the user flag list. Otherwise,
+ * update the system flag list.
*/
- protected function _save()
+ protected function _save($user = true)
{
- $GLOBALS['prefs']->setValue('msgflags', json_encode($this->_flags));
+ global $prefs;
+
+ if ($user) {
+ if (!$prefs->isLocked('msgflags_user')) {
+ $prefs->setValue('msgflags_user', json_encode($this->_userflags));
+ }
+ } elseif (!$prefs->isLocked('msgflags')) {
+ $prefs->setValue('msgflags', json_encode(array_diff_key($this->_flags, $this->_userflags)));
+ }
}
/**
return;
}
- $this->_flags = json_decode($GLOBALS['prefs']->getValue('msgflags'), true);
+ $this->_userflags = json_decode($GLOBALS['prefs']->getValue('msgflags_user'), true);
+ $this->_flags = array_merge(
+ $this->_userflags,
+ json_decode($GLOBALS['prefs']->getValue('msgflags'), true)
+ );
/* Sanity checking. */
if (is_array($this->_flags)) {
for ($i = 0;; ++$i) {
$curr = self::PREFIX . $i;
if (!isset($this->_flags[$curr])) {
- $this->_flags[$curr] = array(
+ $entry = array(
// 'a' => These flags are not shown in mimp
// TODO: Generate random background
'b' => '#ffffff',
't' => 'imapp'
);
+ $this->_flags[$curr] = $entry;
+ $this->_userflags[$curr] = $entry;
+
$this->_save();
return $curr;
}
$this->_flags[$label][$key] = $val;
}
- $this->_save();
+ $this->_save(isset($this->_updateflags[$label]));
}
}
if (isset($this->_flags[$label]) &&
$this->_flags[$label]['l'] &&
!empty($this->_flags[$label]['d'])) {
- unset($this->_flags[$label]);
+ unset($this->_flags[$label], $this->_userflags[$label]);
$this->_save();
return true;
}