- db_delete('wfpl_session_data', 'where session_id=%i && name=%"', $GLOBALS['session_id'], $name);
- db_insert('wfpl_session_data', 'session_id,name,value', $GLOBALS['session_id'], $name, $value);
+ init_session();
+ if (isset($GLOBALS['wfpl_session']['value'][$name])) {
+ if ($GLOBALS['wfpl_session']['value'][$name] === $value) {
+ return;
+ }
+ }
+ $GLOBALS['wfpl_session']['value'][$name] = $value;
+ _sync_session();
+}
+
+# save data into the session
+# values can be anything json_encode()able
+function session_sets($assoc) {
+ init_session();
+ $dirty = false;
+ foreach ($assoc as $name => &$value) {
+ if (isset($GLOBALS['wfpl_session']['value'][$name])) {
+ if ($GLOBALS['wfpl_session']['value'][$name] === $value) {
+ continue;
+ }
+ }
+ $GLOBALS['wfpl_session']['value'][$name] = $value;
+ $dirty = true;
+ }
+ if ($dirty) {
+ _sync_session();
+ }
+}
+
+# remove variable from the session
+# with no args: clear all
+function session_clear($name = -1) {
+ if(!session_exists()) {
+ return;
+ }
+ if ($name === -1) {
+ if (count($GLOBALS['wfpl_session']['value']) > 0) {
+ $GLOBALS['wfpl_session']['value'] = array();
+ _sync_session();
+ }
+ } elseif (isset($GLOBALS['wfpl_session']['value'][$name])) {
+ unset($GLOBALS['wfpl_session']['value'][$name]);
+ _sync_session();
+ }