function on_session_write($key, $val)
{
    $result = xanth_db_query("SELECT * FROM sessions WHERE session_id ='%s'", $key);
    if (!xanth_db_fetch_array($result)) {
        xanth_db_query("INSERT INTO sessions(session_id,session_data,session_timestamp) VALUES('%s','%s',NOW())", $key, $val);
    } else {
        xanth_db_query("UPDATE sessions SET session_data = '%s',session_timestamp = NOW() WHERE session_id = '%s'", $val, $key);
    }
    return '';
}
/**
* Return last inserted id or NULL on error
*/
function xanth_db_get_last_id()
{
    $result = xanth_db_query('SELECT LAST_INSERT_ID() as id');
    if ($row = xanth_db_fetch_array($result)) {
        return $row['id'];
    }
    return NULL;
}
 /**
  *
  */
 function disable()
 {
     if ($this->exists()) {
         $result = xanth_db_query("SELECT enabled FROM modules WHERE name = '%s'", $this->name);
         if ($row = xanth_db_fetch_array($result)) {
             if ($row['enabled']) {
                 xanth_db_query("UPDATE modules SET enabled = 0 WHERE name = '%s'", $this->name);
             }
         }
         return true;
     }
     return false;
 }
 /**
  *
  */
 function load()
 {
     global $xanth_settings;
     $result = xanth_db_query("SELECT * FROM settings");
     $xanth_settings = xanth_db_fetch_array($result);
 }
 /**
  * List all box in an area.
  */
 function find($area = '')
 {
     $boxes = array();
     if (empty($area)) {
         $result = xanth_db_query("SELECT * FROM box");
     } else {
         $result = xanth_db_query("SELECT * FROM box WHERE area = '%s'", $area);
     }
     while ($row = xanth_db_fetch_array($result)) {
         $current_box = new xBox($row['name'], $row['title'], $row['content'], $row['content_format'], $row['is_user_defined'], $row['area']);
         if (!$current_box->user_defined) {
             //retrieve built-in box content
             $current_box->content = xanth_invoke_mono_hook(MONO_HOOK_CREATE_BOX_CONTENT, $current_box->name);
         } else {
             $content_format = new xContentFormat($row['content_format'], '');
             $current_box->content = $content_format->apply_to($current_box->content);
         }
         $boxes[] = $current_box;
     }
     return $boxes;
 }
 /**
  *
  */
 function check_current_user_access($access_rule)
 {
     if (xanth_conf_get('debug', FALSE)) {
         if (!xAccessRule::exists($access_rule)) {
             xanth_log(LOG_LEVEL_DEBUG, 'Access rule "' . $access_rule . '" does not exists', 'User');
         }
     }
     $userid = xUser::get_current_userid();
     if ($userid !== NULL) {
         //if user has admin role bypass check
         $result = xanth_db_query("SELECT * FROM  user_to_role WHERE userid = %d AND roleName = '%s'", $userid, 'administrator');
         if ($row = xanth_db_fetch_array($result)) {
             return TRUE;
         }
         //select other roles
         $result = xanth_db_query("SELECT role_access_rule.access_rule FROM user_to_role,role_access_rule WHERE \r\n\t\t\t\tuser_to_role.userid = %d AND (role_access_rule.roleName = user_to_role.roleName OR role_access_rule.roleName = '%s') \r\n\t\t\t\tAND\trole_access_rule.access_rule = '%s'", $userid, 'authenticated', $access_rule);
     } else {
         $result = xanth_db_query("SELECT role_access_rule.access_rule FROM role_access_rule WHERE \r\n\t\t\t\trole_access_rule.roleName = '%s' AND role_access_rule.access_rule = '%s'", 'anonymous', $access_rule);
     }
     if ($row = xanth_db_fetch_array($result)) {
         return TRUE;
     }
     return FALSE;
 }