/** * Add an element to the site menu * * @static * @access public * @param string [$ctl] Controller name * @param string [$name] Name that will be displayed * @return boolean */ public static function add_to_menu($ctl, $name) { try { $db =& Database::load(); $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'site_menu'; $to_read['value_types'][':t'] = 'str'; $setting = $db->read($to_read); if (empty($setting)) { $setting = new Setting(); $setting->_name = 'Site Menu'; $setting->_type = 'site_menu'; $setting->_data = json_encode(array(array('ctl' => $ctl, 'name' => $name))); $setting->create(); } else { $setting = new Setting($setting[0]['SETTING_ID']); $data = json_decode($setting->_data, true); $data[] = array('ctl' => $ctl, 'name' => $name); $setting->_data = json_encode($data); $setting->update('_data', 'str'); } return true; } catch (Exception $e) { return false; } }
/** * Logout a user * * @access public */ public function logout() { $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'user_' . VSession::user_id(); $to_read['value_types'][':t'] = 'str'; $res = $this->_db->read($to_read); if (empty($res)) { $setting = new Setting(); $setting->_name = 'User preferences for "' . VSession::username() . '"'; $setting->_type = 'user_' . VSession::user_id(); $setting->_data = json_encode(array('last_visit' => date('Y-m-d H:i:s'), 'timeline' => array())); $setting->create(); } else { $setting = new Setting($res[0]['SETTING_ID']); $setting->_data = json_decode($setting->_data, true); $data = $setting->_data; $data['last_visit'] = date('Y-m-d H:i:s'); $setting->_data = json_encode($data); $setting->update('_data', 'str'); } session_destroy(); header('Location: index.php?ns=session&ctl=login&loggedout=true'); }
/** * Delete a role * * @access private */ private function delete() { if (VGet::action(false) == 'delete' && !in_array(VGet::role(), array('administrator', 'editor', 'author')) && $this->_user['delete_content']) { try { $to_read['table'] = 'user'; $to_read['columns'] = array('USER_ID'); $to_read['condition_columns'][':r'] = 'user_role'; $to_read['condition_select_types'][':r'] = '='; $to_read['condition_values'][':r'] = VGet::role(); $to_read['value_types'][':r'] = 'str'; $users = $this->_db->read($to_read); if (!empty($users)) { throw new Exception('Can\'t delete the role "' . ucfirst(VGet::role()) . '" because a user is using it!'); } $to_read = null; $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'role'; $to_read['value_types'][':t'] = 'str'; $to_read['condition_types'][':n'] = 'AND'; $to_read['condition_columns'][':n'] = 'setting_name'; $to_read['condition_select_types'][':n'] = '='; $to_read['condition_values'][':n'] = VGet::role(); $to_read['value_types'][':n'] = 'str'; $role = $this->_db->read($to_read); $role = new Setting($role[0]['SETTING_ID']); $role->delete(); $to_read = null; $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'all_roles'; $to_read['value_types'][':t'] = 'str'; $roles = $this->_db->read($to_read); $roles = new Setting($roles[0]['SETTING_ID']); $array = json_decode($roles->_data, true); foreach ($array as $key => $value) { if ($value == VGet::role()) { unset($array[$key]); } } $roles->_data = json_encode($array); $roles->update('_data', 'str'); $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::deleted($result); } elseif (VGet::action(false) == 'delete' && !$this->_user['delete_content']) { $this->_action_msg = ActionMessages::action_no_perm(); } }