Ejemplo n.º 1
0
/**
 * @param $subject_id
 * @param $event_id
 * @return bool
 * Determine whether all surveys for this time point are complete.
 */
function is_t_complete($subject_id, $event_id) {
	if (isset($subject_id) && isset($event_id)) {
		global $Proj;
		$fields = array();
		$complete = true;
		$surveys_query = "SELECT form_name FROM redcap_surveys WHERE project_id = '$Proj->project_id'";
		$surveys_result = db_query($surveys_query);
		if ($surveys_result) {
			while ($survey_row = db_fetch_array($surveys_result)) {
				if ($Proj->validateFormEvent($survey_row['form_name'], $event_id)) {
					$fields[] = $survey_row['form_name'] . '_complete';
				}
			}
			$data = REDCap::getData('array', $subject_id, $fields, $event_id);
			foreach ($data[$subject_id][$event_id] AS $key => $value) {
				if ($value != '2') {
					$complete = false;
				}
			}
			db_free_result($surveys_result);
			return $complete;
		}
	} else {
		return false;
	}
}
Ejemplo n.º 2
0
 /**
     @param mask_group - if an array, then will use first group that has values defined.
 */
 function TitleMask($mask_group = NULL)
 {
     if ($mask_group !== NULL) {
         if (is_array($mask_group)) {
             while (list(, $group) = each($mask_group)) {
                 $results = fetch_title_display_mask_rs($group);
                 if ($results) {
                     $this->_mask_group = $group;
                     break;
                 }
             }
         } else {
             $this->_mask_group = $mask_group;
             $results = fetch_title_display_mask_rs($mask_group);
         }
         $default_found = FALSE;
         if ($results) {
             while ($title_display_mask_r = db_fetch_assoc($results)) {
                 if ($title_display_mask_r['s_item_type_group'] == '*' && $title_display_mask_r['s_item_type'] == '*') {
                     $default_found = TRUE;
                 }
                 $this->_title_mask_rs[] = $title_display_mask_r;
             }
             db_free_result($results);
         }
         // fall back on a default if none defined
         if (!$default_found) {
             $this->_title_mask_rs[] = array('s_item_type_group' => '*', 's_item_type' => '*', 'display_mask' => '{title}');
         }
     }
 }
Ejemplo n.º 3
0
function get_announcements_block()
{
    $buffer = '';
    if (is_user_granted_permission(PERM_ADMIN_ANNOUNCEMENTS)) {
        // include a login warning if user password and email are still the defaults
        if (get_opendb_session_var('user_id') == 'admin') {
            $announcements_rs = get_admin_announcements_rs();
            while (list(, $announcement_r) = each($announcements_rs)) {
                $buffer .= "<li><h4>" . $announcement_r['heading'] . "</h4>\n\t\t\t\t\t<p class=\"content\">" . $announcement_r['message'] . "<a class=\"adminLink\" href=\"" . $announcement_r['link'] . "\">" . $announcement_r['link_text'] . "</a></p>";
            }
        }
    }
    if (get_opendb_config_var('welcome.announcements', 'enable') !== FALSE && is_user_granted_permission(PERM_VIEW_ANNOUNCEMENTS)) {
        $results = fetch_announcement_rs('submit_on', 'DESC', 0, get_opendb_config_var('welcome.announcements', 'display_count'), 'Y', 'Y');
        if ($results) {
            while ($announcement_r = db_fetch_assoc($results)) {
                $buffer .= "<li><h4>" . $announcement_r['title'] . "</h4>";
                $buffer .= "<small class=\"submitDate\">" . get_localised_timestamp(get_opendb_config_var('welcome.announcements', 'datetime_mask'), $announcement_r['submit_on']) . "</small>";
                $buffer .= "<p class=\"content\">" . nl2br($announcement_r['content']) . "</p></li>";
            }
            db_free_result($results);
        }
    }
    if (strlen($buffer) > 0) {
        return "\n<div id=\"announcements\">" . "<h3>" . get_opendb_lang_var('announcements') . "</h3>" . "\n<ul>" . $buffer . "\n</ul></div>";
    } else {
        return NULL;
    }
}
function checkban(string $login, bool $connect = false) : bool
{
    global $session;
    $accounts = db_prefix('accounts');
    $bans = db_prefix('accounts');
    $today = date('Y-m-d');
    $sql = db_query("SELECT lastip, uniquid, banoverride, superuser FROM {$accounts}\n        WHERE login = '******'");
    $row = db_fetch_assoc($sql);
    if ($row['banoverride'] || $row['superuser'] & ~SU_DOESNT_GIVE_GROTTO) {
        return false;
    }
    db_free_result($sql);
    $sql = db_query("SELECT * FROM {$bans}\n        WHERE (\n            (ipfilter = '{$row['lastip']}' OR ipfilter = '{$_SERVER['REMOTE_ADDR']}')\n            OR (uniqueid = '{$row['uniqueid']}' OR uniqueid = '{$_COOKIE['lgi']}')\n        )\n        AND (banexpire = '000-00-00' OR banexpire >= '{$today}')");
    if (db_num_rows($sql) > 0) {
        if ($connect) {
            $session = [];
            tlschema('ban');
            $session['message'] .= translate_inline('`n`4You fall under a ban currently in place on this website:');
            while ($row = db_fetch_assoc($sql)) {
                $session['message'] .= "`n{$row['banreason']}`n";
                if ($row['banexpire'] == '0000-00-00') {
                    $session['message'] .= translate_inline("`\$This ban is permanent!`0");
                } else {
                    $session['message'] .= sprintf_translate("`^This ban will be removed `\$after`^ %s.`0", date("M d, Y", strtotime($row['banexpire'])));
                }
                db_query("UPDATE {$bans}\n                    SET lasthit = '{$today} 00:00:00'\n                    WHERE ipfilter = '{$row['ipfilter']}'\n                    AND uniqueid = '{$row['uniqueid']}'\n                    ");
            }
            $session['message'] .= translate_inline("`n`4If you wish, you may appeal your ban with the petition link.");
            tlschema();
            header('Location: home.php');
        }
        return true;
    }
    return false;
}
function cw_review_get_management_reviews_count($where = "", $orderby = "", $limit = "")
{
    $count_query = cw_review_get_reviews_query($where, $orderby, $limit);
    $_res = db_query($count_query);
    $total_items = db_num_rows($_res);
    db_free_result($_res);
    return $total_items;
}
Ejemplo n.º 6
0
function site_hminfo_exists($id)
{
    $query = "SELECT 'x' FROM site_hminfo WHERE id = {$id}";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        db_free_result($result);
        return TRUE;
    }
    //else
    return FALSE;
}
function do_forced_nav($anonymous, $overrideforced)
{
    global $baseaccount, $session, $REQUEST_URI;
    rawoutput("<!--\nAllowAnonymous: " . ($anonymous ? "True" : "False") . "\nOverride Forced Nav: " . ($overrideforced ? "True" : "False") . "\n-->");
    if (isset($session['loggedin']) && $session['loggedin']) {
        $sql = "SELECT *  FROM " . db_prefix("accounts") . " WHERE acctid = '" . $session['user']['acctid'] . "'";
        $result = db_query($sql);
        if (db_num_rows($result) == 1) {
            $session['user'] = db_fetch_assoc($result);
            $baseaccount = $session['user'];
            $session['bufflist'] = unserialize($session['user']['bufflist']);
            if (!is_array($session['bufflist'])) {
                $session['bufflist'] = array();
            }
            $session['user']['dragonpoints'] = unserialize($session['user']['dragonpoints']);
            $session['user']['prefs'] = unserialize($session['user']['prefs']);
            if (!is_array($session['user']['dragonpoints'])) {
                $session['user']['dragonpoints'] = array();
            }
            if (is_array(unserialize($session['user']['allowednavs']))) {
                $session['allowednavs'] = unserialize($session['user']['allowednavs']);
            } else {
                $session['allowednavs'] = array($session['user']['allowednavs']);
            }
            if (!$session['user']['loggedin'] || date("U") - strtotime($session['user']['laston']) > getsetting("LOGINTIMEOUT", 900)) {
                $session = array();
                redirect("index.php?op=timeout", "Account not logged in but session thinks they are.");
            }
        } else {
            $session = array();
            $session['message'] = translate_inline("`4Error, your login was incorrect`0", "login");
            redirect("index.php", "Account Disappeared!");
        }
        db_free_result($result);
        //check the nav exists in the session's allowednavs array
        if (isset($session['allowednavs'][$REQUEST_URI]) && $session['allowednavs'][$REQUEST_URI] && $overrideforced !== true) {
            //The nav is fine
            //clear the navs - more navs will be added as the script the player is currently viewing loads and executes
            $session['allowednavs'] = array();
        } else {
            if ($overrideforced !== true) {
                //This nav is not fine at all.  Redirect the player to badnav.php.
                $session['badnav'] = 1;
                redirect("badnav.php", "Navigation not allowed to {$REQUEST_URI}");
            }
        }
    } else {
        if (!$anonymous) {
            $session['message'] = translate_inline("You are not logged in, this may be because your session timed out.", "login");
            redirect("index.php?op=timeout&nli=true", "Not logged in: {$REQUEST_URI}");
        }
    }
}
Ejemplo n.º 8
0
function fetch_s_address_type_r($s_address_type)
{
    $query = "SELECT s_address_type, display_order, description, closed_ind FROM s_address_type WHERE s_address_type = '{$s_address_type}'";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $found = db_fetch_assoc($result);
        db_free_result($result);
        return $found;
    }
    //else
    return FALSE;
}
Ejemplo n.º 9
0
function db_session_read($SID)
{
    $query = "SELECT value FROM php_session " . " WHERE SID = '{$SID}' AND " . " expiration > " . time();
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $found = db_fetch_assoc($result);
        db_free_result($result);
        return $found['value'];
    } else {
        return '';
    }
}
Ejemplo n.º 10
0
function fetch_max_site_plugin_link_order_no($site_type)
{
    $query = "SELECT MAX(order_no) as max_order_no " . "FROM s_site_plugin_link " . "WHERE site_type = '{$site_type}'";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $site_plugin_r = db_fetch_assoc($result);
        db_free_result($result);
        return $site_plugin_r['max_order_no'];
    }
    //else
    return FALSE;
}
Ejemplo n.º 11
0
/**
If called from insert process, the table has been locked
*/
function is_exists_s_item_listing_conf($silc_id)
{
    if (strlen($silc_id) > 0) {
        $query = "SELECT 'x' FROM s_item_listing_conf WHERE id = {$silc_id}";
        $result = db_query($query);
        if ($result && db_num_rows($result) > 0) {
            db_free_result($result);
            return TRUE;
        }
    }
    //else
    return FALSE;
}
Ejemplo n.º 12
0
function fetch_s_item_type_group_cnt()
{
    $query = "SELECT count('x') as count FROM s_item_type_group";
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $found = db_fetch_assoc($result);
        db_free_result($result);
        if ($found !== FALSE) {
            return (int) $found['count'];
        }
    }
    return FALSE;
}
Ejemplo n.º 13
0
 function setCategories($categories)
 {
     query('DELETE FROM ' . prefix('news2cat') . ' WHERE `news_id`=' . $this->getID());
     $result = query("SELECT * FROM " . prefix('news_categories') . " ORDER BY titlelink");
     if ($result) {
         while ($cat = db_fetch_assoc($result)) {
             if (in_array($cat['titlelink'], $categories)) {
                 query("INSERT INTO " . prefix('news2cat') . " (cat_id, news_id) VALUES ('" . $cat['id'] . "', '" . $this->getID() . "')");
             }
         }
         db_free_result($result);
     }
 }
Ejemplo n.º 14
0
function is_exists_borrowed_items_for_status_type($s_status_type, $borrowed_items_only = FALSE)
{
    $query = "SELECT 'x' " . "FROM item_instance ii, borrowed_item bi " . "WHERE ii.item_id = bi.item_id AND " . "ii.instance_no = bi.instance_no AND " . "ii.s_status_type = '{$s_status_type}' ";
    if ($borrowed_items_only) {
        $query .= "AND bi.status = 'B'";
    }
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        db_free_result($result);
        return TRUE;
    }
    //else
    return FALSE;
}
Ejemplo n.º 15
0
function fetch_interest_level($item_id, $instance_no, $user_id)
{
    $query = "SELECT level" . " FROM user_item_interest i" . " WHERE i.item_id = {$item_id} AND i.instance_no = {$instance_no} AND i.user_id = '{$user_id}'";
    //    	opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, "query:" . $query);
    $result = db_query($query);
    if ($result && db_num_rows($result) > 0) {
        $found = db_fetch_assoc($result);
        db_free_result($result);
        // 	   	opendb_logger(OPENDB_LOG_INFO, __FILE__, __FUNCTION__, "level:" . $found['level']);
        return trim($found['level']);
    } else {
        return FALSE;
    }
}
Ejemplo n.º 16
0
function fetch_s_file_type_alt_extension_r($content_type)
{
    $query = "SELECT extension " . "FROM s_file_type_extension " . "WHERE content_type = '{$content_type}' AND default_ind <> 'Y' " . "ORDER BY extension";
    $results = db_query($query);
    if ($results && db_num_rows($results) > 0) {
        $alt_extensions_r = array();
        while ($extension_r = db_fetch_assoc($results)) {
            $alt_extensions_r[] = $extension_r['extension'];
        }
        db_free_result($results);
        return $alt_extensions_r;
    } else {
        return FALSE;
    }
}
function loadsettings()
{
    global $settings;
    if (!is_array($settings)) {
        $settings = datacache('game-settings');
        if (!is_array($settings)) {
            $settings = [];
            $sql = db_query("SELECT * FROM " . db_prefix('settings'));
            while ($row = db_fetch_assoc($sql)) {
                $settings[$row['setting']] = $row['value'];
            }
            db_free_result($sql);
            updatedatacache('game-settings', $settings);
        }
    }
}
Ejemplo n.º 18
0
/**
 * Returns a list of database tables for the installation
 * @return type
 */
function getDBTables()
{
    $tables = array();
    $prefix = trim(prefix(), '`');
    $resource = db_show('tables');
    if ($resource) {
        $result = array();
        while ($row = db_fetch_assoc($resource)) {
            $table = array_shift($row);
            $table = substr($table, strlen($prefix));
            $tables[] = $table;
        }
        db_free_result($resource);
    }
    return $tables;
}
Ejemplo n.º 19
0
/**
	This function will return a complete table of all links valid
	for this item_type.

	This is useful because it allows the use of a site plugin for
	generating links only, by specifying as the default site type.
*/
function get_site_plugin_links($page_title, $item_r)
{
    $pageContents = '';
    $results = fetch_site_plugin_rs($item_r['s_item_type']);
    if ($results) {
        $titleMaskCfg = new TitleMask();
        $pageContents = "<ul class=\"sitepluginLinks\">";
        while ($site_plugin_type_r = db_fetch_assoc($results)) {
            if (is_exists_site_plugin($site_plugin_type_r['site_type'])) {
                $site_plugin_conf_rs = get_site_plugin_conf_r($site_plugin_type_r['site_type']);
                if (strlen($site_plugin_type_r['image']) > 0) {
                    $link_text = theme_image("images/site/" . $site_plugin_type_r['image'], htmlspecialchars($site_plugin_type_r['title']));
                } else {
                    $link_text = $site_plugin_type_r['title'];
                }
                $results2 = fetch_site_plugin_link_rs($site_plugin_type_r['site_type'], $item_r['s_item_type']);
                if ($results2) {
                    while ($site_plugin_link_r = db_fetch_assoc($results2)) {
                        $parse_url = NULL;
                        if (strlen($site_plugin_link_r['url']) > 0 && is_exists_site_item_attribute($site_plugin_type_r['site_type'], $item_r['item_id'], $item_r['instance_no'])) {
                            $parse_url = $site_plugin_link_r['url'];
                        } else {
                            if (strlen($site_plugin_link_r['title_url']) > 0) {
                                $parse_url = $site_plugin_link_r['title_url'];
                            }
                        }
                        if ($parse_url != NULL) {
                            $titleMaskCfg->reset();
                            $parse_url = trim($titleMaskCfg->expand_title($item_r, $parse_url, $site_plugin_conf_rs));
                            if (strlen($parse_url) > 0) {
                                $pageContents .= "<li><a href=\"" . $parse_url . "\" target=\"_new\">{$link_text}";
                                $pageContents .= "<span class=\"sitePluginDescription\">" . $site_plugin_link_r['description'] . "</span>";
                                $pageContents .= "</a></li>";
                            }
                        }
                    }
                    //while
                    db_free_result($results2);
                }
            }
        }
        //while
        db_free_result($results);
        $pageContents .= "</ul>";
        return $pageContents;
    }
}
Ejemplo n.º 20
0
 static function clones()
 {
     global $_zp_current_admin_obj;
     $clones = array();
     if ($result = query('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="clone"')) {
         while ($row = db_fetch_assoc($result)) {
             if (file_exists($row['aux'] . '/' . DATA_FOLDER . '/zenphoto.cfg.php')) {
                 $clones[$row['aux']] = $row['data'] . '/';
                 $_SESSION['admin'][bin2hex($row['aux'])] = serialize($_zp_current_admin_obj);
             } else {
                 query('DELETE FROM ' . prefix('plugin_storage') . ' WHERE `id` = ' . $row['id']);
             }
         }
         db_free_result($result);
     }
     return $clones;
 }
function checkban($login = false)
{
    global $session;
    if (isset($session['banoverride']) && $session['banoverride']) {
        return false;
    }
    if ($login === false) {
        $ip = $_SERVER['REMOTE_ADDR'];
        $id = $_COOKIE['lgi'];
    } else {
        $sql = "SELECT lastip,uniqueid,banoverride,superuser FROM " . db_prefix("accounts") . " WHERE login='******'";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        if ($row['banoverride'] || $row['superuser'] & ~SU_DOESNT_GIVE_GROTTO) {
            $session['banoverride'] = true;
            return false;
        }
        db_free_result($result);
        $ip = $row['lastip'];
        $id = $row['uniqueid'];
    }
    $sql = "SELECT * FROM " . db_prefix("bans") . " where ((substring('{$ip}',1,length(ipfilter))=ipfilter AND ipfilter<>'') OR (uniqueid='{$id}' AND uniqueid<>'')) AND (banexpire='0000-00-00' OR banexpire>='" . date("Y-m-d") . "')";
    $result = db_query($sql);
    if (db_num_rows($result) > 0) {
        $session = array();
        tlschema("ban");
        $session['message'] .= translate_inline("`n`4You fall under a ban currently in place on this website:`n");
        while ($row = db_fetch_assoc($result)) {
            $session['message'] .= $row['banreason'] . "`n";
            if ($row['banexpire'] == '0000-00-00') {
                $session['message'] .= translate_inline("  `\$This ban is permanent!`0");
            } else {
                $session['message'] .= sprintf_translate("  `^This ban will be removed `\$after`^ %s.`0", date("M d, Y", strtotime($row['banexpire'])));
            }
            $sql = "UPDATE " . db_prefix("bans") . " SET lasthit='" . date("Y-m-d H:i:s") . "' WHERE ipfilter='{$row['ipfilter']}' AND uniqueid='{$row['uniqueidid']}'";
            db_query($sql);
            $session['message'] .= "`n";
        }
        $session['message'] .= translate_inline("`4If you wish, you may appeal your ban with the petition link.");
        tlschema();
        header("Location: index.php");
        exit;
    }
    db_free_result($result);
}
Ejemplo n.º 22
0
function get_attribute_type_rs($attribute_type_rs)
{
    global $_attribute_type_list_rs;
    if (!is_array($_attribute_type_list_rs)) {
        $results = fetch_item_type_s_attribute_type_rs();
        if ($results) {
            while ($attribute_type_r = db_fetch_assoc($results)) {
                $_attribute_type_list_rs[] = array('value' => $attribute_type_r['s_attribute_type'], 'display' => $attribute_type_r['description']);
            }
            db_free_result($results);
        }
    }
    reset($_attribute_type_list_rs);
    while (list(, $_attribute_type_list_r) = each($_attribute_type_list_rs)) {
        $attribute_type_rs[] = $_attribute_type_list_r;
    }
    return $attribute_type_rs;
}
Ejemplo n.º 23
0
 public function titleSearch($params_r)
 {
     $titleMaskCfg = new TitleMask('item_listing');
     // if no limit provided, provide one!
     if (empty($params_r['limit'])) {
         $params_r['limit'] = 10;
     }
     if (empty($params_r['title_match'])) {
         $params_r['title_match'] = 'partial';
     }
     $results = fetch_item_listing_rs($params_r, array(), 'title', 'ASC', 0, $params_r['limit']);
     while ($item_r = db_fetch_assoc($results)) {
         $item_r['title'] = $titleMaskCfg->expand_item_title($item_r);
         $jsonResults[] = $item_r;
     }
     db_free_result($results);
     return $jsonResults;
 }
Ejemplo n.º 24
0
 function __construct()
 {
     global $_zp_authority, $_userAddressFields;
     $firstTime = false;
     $tablecols = db_list_fields('administrators');
     foreach ($tablecols as $key => $datum) {
         if ($datum['Field'] == 'custom_data') {
             $firstTime = true;
             enableExtension('userAddressFields', true);
             break;
         }
     }
     parent::constructor('userAddressFields', self::fields());
     if ($firstTime) {
         //	migrate the custom data user data
         $result = query('SELECT * FROM ' . prefix('administrators') . ' WHERE `valid`!=0');
         if ($result) {
             while ($row = db_fetch_assoc($result)) {
                 $custom = getSerializedArray($row['custom_data']);
                 if (!empty($custom)) {
                     $sql = 'UPDATE ' . prefix('administrators') . ' SET ';
                     foreach ($custom as $field => $val) {
                         $sql .= '`' . $field . '`=' . db_quote($val) . ',';
                     }
                     setupQuery($sql);
                 }
             }
             db_free_result($result);
         }
         setupQuery('ALTER TABLE ' . prefix('administrators') . ' DROP `custom_data`');
     }
     $cloneid = bin2hex(FULLWEBPATH);
     if (OFFSET_PATH == 2 && isset($_SESSION['admin'][$cloneid])) {
         $user = unserialize($_SESSION['admin'][$cloneid]);
         $user2 = $_zp_authority->getAnAdmin(array('`user`=' => $user->getUser(), '`pass`=' => $user->getPass(), '`valid`=' => 1));
         if ($user2) {
             foreach (userAddressFields::fields() as $field) {
                 $user2->set($field['name'], $user->get($field['name']));
             }
             $user2->save();
         }
     }
 }
Ejemplo n.º 25
0
 function __construct()
 {
     global $_userAddressFields;
     $firstTime = extensionEnabled('userAddressFields') && is_null(getOption('userAddressFields_addedFields'));
     parent::constructor('userAddressFields', self::fields());
     if ($firstTime) {
         //	migrate the custom data user data
         $result = query('SELECT * FROM ' . prefix('administrators') . ' WHERE `valid`!=0');
         if ($result) {
             while ($row = db_fetch_assoc($result)) {
                 $custom = getSerializedArray($row['custom_data']);
                 if (!empty($custom)) {
                     $sql = 'UPDATE ' . prefix('administrators') . ' SET ';
                     foreach ($custom as $field => $val) {
                         $sql .= '`' . $field . '`=' . db_quote($val) . ',';
                     }
                     $sql .= '`custom_data`=NULL WHERE `id`=' . $row['id'];
                     query($sql);
                 }
             }
             db_free_result($result);
         }
     }
 }
function cw_table2csv($tab, $delimiter = ';')
{
    global $tables;
    $fn = cw_create_csv_filename($tab);
    $h = fopen($fn, 'w');
    fwrite($h, "[{$tab}]\n");
    $res = db_query("select * from {$tables[$tab]}");
    $first_time = true;
    $title = '';
    while ($val = db_fetch_array($res)) {
        if ($first_time) {
            foreach ($val as $k => $v) {
                $title .= "!{$k}\t\t";
            }
            $title = str_replace("\t\t", $delimiter, trim($title));
            fwrite($h, "{$title}\n");
            $first_time = false;
        }
        fputcsv($h, $val, $delimiter);
    }
    db_free_result($res);
    fclose($h);
    //cw_csv2table($fn);
}
function loadsettings()
{
    global $settings;
    // as this seems to be a common complaint, examine the execution path
    // of this function, it will only load the settings once per page hit,
    // in subsequent calls to this function, $settings will be an array,
    // thus this function will do nothing.
    // slight change in 1.1.1 ... let's store a serialized array instead of a cached query
    // we need it too often and the for/while construct necessary is just too much for it.
    if (!is_array($settings)) {
        $settings = datacache("game-settings");
        if (!is_array($settings)) {
            $settings = array();
            $sql = "SELECT * FROM " . db_prefix("settings");
            $result = db_query($sql);
            //db_query_cached($sql,"game-settings");
            while ($row = db_fetch_assoc($result)) {
                $settings[$row['setting']] = $row['value'];
            }
            db_free_result($result);
            updatedatacache("game-settings", $settings);
        }
    }
}
Ejemplo n.º 28
0
 /**
  *	fetchData - re-fetch the data for this ArtifactFile from the database.
  *
  *	@param	int	The file_id.
  *	@return	boolean	success.
  */
 function fetchData($id)
 {
     global $Language;
     $sql = "SELECT af.id, af.artifact_id, af.description, af.bin_data, af.filename, af.filesize, af.filetype, af.adddate, af.submitted_by, user.user_name, user.realname \n                FROM artifact_file af, user \n                WHERE (af.submitted_by = user.user_id) and af.id=" . db_ei($id);
     //echo $sql;
     $res = db_query($sql);
     if (!$res || db_numrows($res) < 1) {
         $this->setError('ArtifactFile: ' . $Language->getText('tracker_common_file', 'invalid_id'));
         return false;
     }
     $this->data_array = db_fetch_array($res);
     db_free_result($res);
     return true;
 }
 function dumpTableContent($table, $schema, $fd)
 {
     global $sql_backup_rows;
     if ($fd === false) {
         print "{$schema}\n\n";
     } else {
         fwrite($fd, "{$schema}\n\n");
         echo cw_get_langvar_by_name("lbl_dumping_table_n", array("table" => $table), false, true) . "<br />\n";
     }
     $rows_cnt = 0;
     $current_row = 0;
     $count = cw_query_first_cell("SELECT count(*) FROM " . $table);
     if ($count < 1) {
         return;
     }
     for ($pos = 0; $count > 0; $count -= $sql_backup_rows, $pos += $sql_backup_rows) {
         $local_query = "SELECT * FROM {$table} LIMIT {$pos},{$sql_backup_rows}";
         $result = db_query($local_query);
         if ($result != FALSE) {
             $fields_cnt = mysql_num_fields($result);
             $rows_cnt = mysql_num_rows($result);
             // Checks whether the field is an integer or not
             for ($j = 0; $j < $fields_cnt; $j++) {
                 $field_set[$j] = mysql_field_name($result, $j);
                 $type = mysql_field_type($result, $j);
                 $field_num[$j] = ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || $type == 'timestamp') && (!defined("OVERRIDE_NUM_FIELD") || !constant("OVERRIDE_NUM_FIELD"));
             }
             // Sets the scheme
             $schema_insert = "INSERT INTO {$table} VALUES (";
             $search = array("", "\n", "\r", "");
             //\x08\\x09, not required
             $replace = array('0', '\\n', '\\r', '\\Z');
             $current_row = 0;
             while ($row = mysql_fetch_row($result)) {
                 $current_row++;
                 for ($j = 0; $j < $fields_cnt; $j++) {
                     if (!isset($row[$j])) {
                         $values[] = 'NULL';
                     } else {
                         if ($row[$j] == '0' || $row[$j] != '') {
                             // a number
                             if ($field_num[$j]) {
                                 $values[] = $row[$j];
                             } else {
                                 $values[] = "'" . str_replace($search, $replace, addslashes($row[$j])) . "'";
                             }
                         } else {
                             $values[] = "''";
                         }
                     }
                     // end if
                 }
                 // end for
                 // Extended inserts case
                 $insert_line = $schema_insert . implode(', ', $values) . ')';
                 unset($values);
                 // Send the line
                 if ($fd === false) {
                     print $insert_line . ";\n";
                     flush();
                 } else {
                     fwrite($fd, $insert_line . ";\n");
                     fflush($fd);
                 }
                 // loic1: send a fake header to bypass browser timeout if data
                 //        are bufferized
             }
             // end while
         }
         // end if ($result != FALSE)
         db_free_result($result);
         if ($fd !== false) {
             cw_flush(". ");
         }
     }
     // for
     if ($fd === false) {
         print "\n";
     } else {
         fwrite($fd, "\n");
         echo "<br />";
     }
 }
Ejemplo n.º 30
0
 /**
  * For every image in the album, look for its file. Delete from the database
  * if the file does not exist. Same for each sub-directory/album.
  *
  * @param bool $deep set to true for a thorough cleansing
  */
 function garbageCollect($deep = false)
 {
     if (is_null($this->images)) {
         $this->getImages();
     }
     $result = query("SELECT * FROM " . prefix('images') . " WHERE `albumid` = '" . $this->id . "'");
     $dead = array();
     $live = array();
     $files = $this->loadFileNames();
     // Does the filename from the db row match any in the files on disk?
     while ($row = db_fetch_assoc($result)) {
         if (!in_array($row['filename'], $files)) {
             // In the database but not on disk. Kill it.
             $dead[] = $row['id'];
         } else {
             if (in_array($row['filename'], $live)) {
                 // Duplicate in the database. Kill it.
                 $dead[] = $row['id'];
                 // Do something else here? Compare titles/descriptions/metadata/update dates to see which is the latest?
             } else {
                 $live[] = $row['filename'];
             }
         }
     }
     db_free_result($result);
     if (count($dead) > 0) {
         $sql = "DELETE FROM " . prefix('images') . " WHERE `id` = '" . array_pop($dead) . "'";
         $sql2 = "DELETE FROM " . prefix('comments') . " WHERE `type`='albums' AND `ownerid` = '" . array_pop($dead) . "'";
         foreach ($dead as $id) {
             $sql .= " OR `id` = '{$id}'";
             $sql2 .= " OR `ownerid` = '{$id}'";
         }
         query($sql);
         query($sql2);
     }
     // Get all sub-albums and make sure they exist.
     $result = query("SELECT * FROM " . prefix('albums') . " WHERE `folder` LIKE " . db_quote(db_LIKE_escape($this->name) . '%'));
     $dead = array();
     $live = array();
     // Does the dirname from the db row exist on disk?
     while ($row = db_fetch_assoc($result)) {
         if (!is_dir(ALBUM_FOLDER_SERVERPATH . internalToFilesystem($row['folder'])) || in_array($row['folder'], $live) || substr($row['folder'], -1) == '/' || substr($row['folder'], 0, 1) == '/') {
             $dead[] = $row['id'];
         } else {
             $live[] = $row['folder'];
         }
     }
     db_free_result($result);
     if (count($dead) > 0) {
         $sql = "DELETE FROM " . prefix('albums') . " WHERE `id` = '" . array_pop($dead) . "'";
         $sql2 = "DELETE FROM " . prefix('comments') . " WHERE `type`='albums' AND `ownerid` = '" . array_pop($dead) . "'";
         foreach ($dead as $albumid) {
             $sql .= " OR `id` = '{$albumid}'";
             $sql2 .= " OR `ownerid` = '{$albumid}'";
         }
         query($sql);
         query($sql2);
     }
     if ($deep) {
         foreach ($this->getAlbums(0) as $dir) {
             $subalbum = newAlbum($dir);
             // Could have been deleted if it didn't exist above...
             if ($subalbum->exists) {
                 $subalbum->garbageCollect($deep);
             }
         }
     }
 }