Example #1
0
function query__save_query($json_query, $type, $experiment_id = 0, $properties = array(), $permanent = false)
{
    // type can be participants_search_active, participants_search_all, assign, deassign
    global $expadmin;
    $now = time();
    if ($experiment_id && $permanent) {
        // if this query is supposed to be permanent, then reset current permanent query if any
        $done = query__reset_permanent($experiment_id);
        // for new query
        $properties['is_permanent'] = 1;
        $properties['permanent_start_time'] = time();
        $properties['assigned_count'] = 0;
        $addquery = ", permanent=1";
        $addmessage = lang('activated_as_permanent_query');
    } else {
        $addquery = ", permanent=0";
    }
    $properties_string = property_array_to_db_string($properties);
    $continue = true;
    if ($experiment_id == 0) {
        // check if we already know this query, and if so, just update the record
        $pars = array(':json_query' => $json_query);
        $query = "SELECT * FROM " . table('queries') . "\n                WHERE json_query= :json_query LIMIT 1";
        $line = orsee_query($query, $pars);
        if (isset($line['query_id'])) {
            $pars = array(':query_time' => $now, ':query_id' => $line['query_id']);
            $query = "UPDATE " . table('queries') . "\n                    SET query_time= :query_time\n                    WHERE query_id= :query_id";
            $done = or_query($query, $pars);
            message(lang('query_existed_now_updated'));
            $continue = false;
        }
    }
    // otherwise, save the query
    if ($continue) {
        if (isset($expadmindata['admin_id'])) {
            $admin_id = $expadmindata['admin_id'];
        } else {
            $admin_id = '';
        }
        $pars = array(':query_time' => $now, ':json_query' => $json_query, ':query_type' => $type, ':experiment_id' => $experiment_id, ':properties' => $properties_string, ':admin_id' => $admin_id);
        $query = "INSERT INTO " . table('queries') . "\n                SET query_time=:query_time,\n                json_query=:json_query,\n                query_type=:query_type,\n                experiment_id=:experiment_id,\n                admin_id=:admin_id,\n                properties=:properties " . $addquery;
        $done = or_query($query, $pars);
        message(lang('query_saved'));
        if (isset($addmessage)) {
            message($addmessage);
        }
    }
    return $done;
}
Example #2
0
    }
}
if ($proceed) {
    $allow = check_allow('experiment_show', 'experiment_main.php');
}
if ($proceed) {
    // load experiment data into array experiment
    $experiment = orsee_db_load_array("experiments", $experiment_id, "experiment_id");
    if (!check_allow('experiment_restriction_override')) {
        check_experiment_allowed($experiment, "admin/experiment_main.php");
    }
}
if ($proceed) {
    // check if we are supposed to deactivate a permanent query
    if ($settings['allow_permanent_queries'] == 'y' && check_allow('experiment_assign_query_permanent_deactivate') && isset($_REQUEST['permanent_deactivate']) && $_REQUEST['permanent_deactivate']) {
        $done = query__reset_permanent($experiment_id);
        redirect('admin/experiment_show.php?experiment_id=' . $experiment_id);
    }
}
if ($proceed) {
    $experiment_total_payment = 0;
    // load sessions if lab experiment
    $sessions = array();
    if ($experiment['experiment_type'] == "laboratory") {
        $pars = array(':experiment_id' => $experiment['experiment_id']);
        $query = "SELECT *\n                FROM " . table('sessions') . "\n                WHERE experiment_id= :experiment_id\n                ORDER BY session_start";
        $result = or_query($query, $pars);
        $min = 0;
        $max = 0;
        $sids = array();
        while ($s = pdo_fetch_assoc($result)) {