Esempio n. 1
0
include "header.php";
if ($proceed) {
    if (isset($_REQUEST['item'])) {
        $item = $_REQUEST['item'];
    } else {
        redirect("admin/");
    }
}
if ($proceed) {
    if (isset($_REQUEST['id'])) {
        $id = $_REQUEST['id'];
    } else {
        $id = "";
    }
    $done = false;
    $formfields = participantform__load();
    $allow_cat = $item;
    foreach ($formfields as $f) {
        if (preg_match("/(select_lang|radioline_lang)/", $f['type']) && $item == $f['mysql_column_name']) {
            $done = true;
            $header = isset($lang[$f['name_lang']]) ? $lang[$f['name_lang']] : $f['name_lang'];
            $new_id = 'time';
            $inputform = 'line';
            $check_allow_content_shortcut = false;
            $allow_cat = 'pform_lang_field';
        }
    }
    if (!$id) {
        $allow = check_allow($allow_cat . '_edit', 'lang_item_main.php?item=' . $item);
    } else {
        $allow = check_allow($allow_cat . '_edit', 'options_main.php');
Esempio n. 2
0
function query__get_pseudo_query_array($posted_array)
{
    global $lang;
    $formfields = participantform__load();
    $pseudo_query_array = array();
    $clevel = 1;
    foreach ($posted_array as $num => $entry) {
        $temp_keys = array_keys($entry);
        $module_string = $temp_keys[0];
        $module_string_array = explode("_", $module_string);
        $module = $module_string_array[0];
        $type = $module_string_array[1];
        if ($module == 'pform') {
            unset($module_string_array[0]);
            unset($module_string_array[1]);
            $pform_formfield = implode("_", $module_string_array);
        } else {
            $pform_formfield = "";
        }
        $params = $entry[$module_string];
        $level = $clevel;
        $op_text = "";
        $text = '';
        $add = true;
        if (isset($params['logical_op']) && $params['logical_op']) {
            $op_text = lang($params['logical_op']);
        }
        switch ($module) {
            case "bracket":
                if ($type == 'open') {
                    $level = $clevel;
                    $clevel++;
                    $text = '(';
                } else {
                    $clevel--;
                    $level = $clevel;
                    $text = ')';
                }
                break;
            case "experimentclasses":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('participants_participated_expclass');
                $text .= ': ' . experiment__experiment_class_field_to_list($params['ms_classes']);
                break;
            case "experimenters":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('participants_participated_experimenters');
                $text .= ': ' . experiment__list_experimenters($params['ms_experimenters'], false, true);
                break;
            case "experimentsassigned":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('participants_were_assigned_to');
                $text .= ': ' . experiment__exp_id_list_to_exp_names($params['ms_experiments']);
                break;
            case "experimentsparticipated":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('participants_have_participated_on');
                $text .= ': ' . experiment__exp_id_list_to_exp_names($params['ms_experiments']);
                break;
            case "statusids":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('participants_of_status');
                $text .= ': ' . participant__status_id_list_to_status_names($params['ms_status']);
                break;
            case "pformtextfields":
                $text = lang('where');
                $text .= ' "' . $params['search_string'] . '" ';
                $text .= query__pseudo_query_not_not($params);
                $text .= lang('in') . ' ';
                if ($params['search_field'] == 'all') {
                    $text .= lang('any_field');
                } else {
                    $text .= $params['search_field'];
                }
                break;
            case "pform":
                $f = array();
                foreach ($formfields as $p) {
                    if ($p['mysql_column_name'] == $pform_formfield) {
                        $f = $p;
                    }
                }
                if (isset($f['mysql_column_name'])) {
                    $text = lang('where') . ' ' . lang($f['name_lang']) . ' ';
                    if ($type == 'numberselect') {
                        $text .= $params['sign'] . $params['fieldvalue'];
                    } elseif ($type == 'simpleselect') {
                        $text .= query__pseudo_query_not_not($params) . '= "' . $params['fieldvalue'] . '"';
                    } else {
                        $text .= query__pseudo_query_not_not($params) . lang('in') . ': ' . participant__select_lang_idlist_to_names($f['mysql_column_name'], $params['ms_' . $pform_formfield]);
                    }
                } else {
                    $add = false;
                }
                break;
            case "noshows":
                $text = lang('where_nr_noshowups_is') . ' ';
                $text .= $params['sign'] . ' ' . $params['count'];
                break;
            case "participations":
                $text = lang('where_nr_participations_is') . ' ';
                $text .= $params['sign'] . ' ' . $params['count'];
                break;
            case "updaterequest":
                $text = lang('where_profile_update_request_is') . ' ';
                if ($params['update_request_status'] == 'y') {
                    $text .= lang('active');
                } else {
                    $text .= lang('inactive');
                }
                break;
            case "activity":
                $text = lang('where') . ' ' . lang($params['activity_type']) . ' ';
                $text .= query__pseudo_query_not_not($params);
                $text .= lang('before_date') . ' ';
                $sesstime_act = ortime__array_to_sesstime($params, 'dt_activity_');
                $text .= ortime__format(ortime__sesstime_to_unixtime($sesstime_act), 'hide_time:true');
                break;
            case "randsubset":
                $text = lang('limit_to_randomly_drawn') . ' ';
                $text .= $params['limit'];
                break;
            case "subsubjectpool":
                $text = query__pseudo_query_not_without($params);
                $text .= ' ' . lang('who_are_in_subjectpool');
                $text .= ': ' . subpools__idlist_to_namelist($params['ms_subpool']);
                break;
        }
        if ($add) {
            $pseudo_query_array[] = array('level' => $level, 'op_text' => $op_text, 'text' => $text);
        }
    }
    return $pseudo_query_array;
}
Esempio n. 3
0
function stats__get_data($condition = array(), $type = 'stats', $restrict = array(), $options = array())
{
    global $settings;
    $conditions = array();
    $pars = array();
    if (is_array($condition) && count($condition) > 0) {
        $conditions[] = $condition['clause'];
        if (isset($condition['pars']) && is_array($condition['pars'])) {
            foreach ($condition['pars'] as $k => $v) {
                $pars[$k] = $v;
            }
        }
    }
    $formfields = participantform__load();
    $pform_fields = array();
    $pform_types = array();
    foreach ($formfields as $f) {
        if (!preg_match("/(textline|textarea)/i", $f['type']) && isset($f['include_in_statistics']) && ($f['include_in_statistics'] == 'pie' || $f['include_in_statistics'] == 'bars')) {
            $pform_fields[] = $f['mysql_column_name'];
            $pform_types[$f['mysql_column_name']] = $f;
        }
    }
    $statfields = array('subpool_id', 'subscriptions', 'status_id');
    foreach ($pform_fields as $field) {
        if (!in_array($field, $statfields)) {
            $statfields[] = $field;
        }
    }
    if ($type == 'stats' && $settings['enable_rules_signed_tracking'] == 'y') {
        if (!in_array('rules_signed', $statfields)) {
            $statfields[] = 'rules_signed';
        }
    } else {
        $exists = array_search('rules_signed', $statfields);
        if ($exists) {
            unset($statfields[$exists]);
        }
    }
    if ($type == 'stats') {
        foreach (array('number_reg', 'number_noshowup', 'last_enrolment', 'last_profile_update', 'last_activity') as $field) {
            if (!in_array($field, $statfields)) {
                $statfields[] = $field;
            }
        }
    }
    $query = "SELECT * from " . table('participants');
    $query_conditions = "";
    if (count($conditions) > 0) {
        $query_conditions .= " WHERE";
        $cond_strings = array();
        foreach ($conditions as $cond) {
            $cond_strings[] = "(" . $cond . ")";
        }
        $query_conditions .= " " . implode(" AND ", $cond_strings);
    }
    $query .= $query_conditions;
    $result = or_query($query, $pars);
    $counts = array();
    $pids = array();
    while ($line = pdo_fetch_assoc($result)) {
        // check whether we should count this participant and (for monthly stats) use this value
        $p_restrict = false;
        foreach ($statfields as $c) {
            $value = $line[$c];
            if (in_array($c, array('last_enrolment', 'last_profile_update', 'last_activity'))) {
                if (!$value) {
                    $value = 0;
                }
                if ($value == 0) {
                    $value = '-';
                } else {
                    $value = date('Ym', $value);
                }
            }
            $value = db_string_to_id_array($value);
            if (count($value) > 0) {
                $this_restrict = true;
                foreach ($value as $v) {
                    if (!isset($restrict[$c][$v])) {
                        $this_restrict = false;
                    }
                }
                if ($this_restrict) {
                    $p_restrict = true;
                }
            } else {
                $value = '-';
                if (isset($restrict[$c][$value])) {
                    $p_restrict = true;
                }
            }
        }
        if (!$p_restrict) {
            $pids[] = $line['participant_id'];
            foreach ($statfields as $c) {
                $value = $line[$c];
                $continue = true;
                if (in_array($c, array('last_enrolment', 'last_profile_update', 'last_activity'))) {
                    if (!$value) {
                        $value = 0;
                    }
                    if (date('Ym', $value) < date('Ym', strtotime("-" . $settings['stats_months_backward'] . " month", time()))) {
                        $continue = false;
                    }
                    if ($value == 0) {
                        $value = '-';
                    } else {
                        $value = date('Ym', $value);
                    }
                }
                if ($continue) {
                    $value = db_string_to_id_array($value);
                    if (count($value) > 0) {
                        foreach ($value as $v) {
                            if (!isset($counts[$c][$v])) {
                                $counts[$c][$v] = 0;
                            }
                            $counts[$c][$v]++;
                        }
                    } else {
                        $value = '-';
                        if (!isset($counts[$c][$value])) {
                            $counts[$c][$value] = 0;
                        }
                        $counts[$c][$value]++;
                    }
                }
            }
        }
    }
    $count_pids = count($pids);
    $pid_condition = "";
    if (count($restrict) > 0) {
        $pid_condition = " AND participant_id IN (" . implode(", ", $pids) . ") ";
    } elseif (count($conditions) == 1 && isset($options['condition_only_on_pid']) && $options['condition_only_on_pid']) {
        $pid_condition = " AND " . $condition['clause'] . " ";
    } elseif ($query_conditions) {
        $pid_condition = " AND participant_id IN (SELECT participant_id FROM " . table('participants') . " " . $query_conditions . ") ";
    }
    // avg. experience (participation in experiments of class x, y, z  at time of experiment)
    $statfields[] = 'experience_avg_experimentclass';
    if ($count_pids > 0) {
        $participated_clause = expregister__get_pstatus_query_snippet("participated");
        $query = "SELECT count(*) as num, experiment_class\n                FROM " . table('participate_at') . " as p, " . table('experiments') . " as e\n                WHERE p.session_id>0 " . $pid_condition . "\n                AND e.experiment_id=p.experiment_id\n                AND e.experiment_class !=''\n                AND " . $participated_clause . " ";
        if (is_array($options) && isset($options['upper_experience_limit'])) {
            $query .= " AND session_id IN (SELECT session_id FROM " . table('sessions') . "\n                        WHERE session_start < " . ortime__unixtime_to_sesstime($options['upper_experience_limit']) . "\n                        AND session_status IN ('completed','balanced') ) ";
        }
        $query .= "GROUP BY experiment_class";
        $result = or_query($query, $pars);
        while ($line = pdo_fetch_assoc($result)) {
            $line['experiment_class'] = db_string_to_id_array($line['experiment_class']);
            foreach ($line['experiment_class'] as $v) {
                if ($v > 0) {
                    if (!isset($counts['experience_avg_experimentclass'][$v])) {
                        $counts['experience_avg_experimentclass'][$v] = 0;
                    }
                    $counts['experience_avg_experimentclass'][$v] += round($line['num'] / $count_pids, 2);
                }
            }
        }
    }
    if ($type == 'report') {
        // avg. count pstatus at time of experiment)
        $statfields[] = 'experience_avg_pstatus';
    }
    if ($count_pids > 0 && $type == 'report') {
        $query = "SELECT count(*) as num, pstatus_id\n                FROM " . table('participate_at') . "\n                WHERE session_id>0 " . $pid_condition;
        if (is_array($options) && isset($options['upper_experience_limit'])) {
            $query .= " AND session_id IN (SELECT session_id FROM " . table('sessions') . "\n                    WHERE session_start < " . ortime__unixtime_to_sesstime($options['upper_experience_limit']) . "\n                    AND session_status IN ('completed','balanced') ) ";
        }
        $query .= "GROUP BY pstatus_id";
        $result = or_query($query, $pars);
        while ($line = pdo_fetch_assoc($result)) {
            $counts['experience_avg_pstatus'][$line['pstatus_id']] = round($line['num'] / $count_pids, 2);
        }
    }
    if ($type == 'stats') {
        // by pstatus: pstatus count // really needed? we have no_noshows, num_reg ...
        // by month: pstatus
        $statfields[] = 'bymonth_pstatus';
        $statfields[] = 'bymonth_noshowrate';
    }
    if ($count_pids > 0 && $type == 'stats') {
        $first_month = date('Ym000000', strtotime("-" . $settings['stats_months_backward'] . " month", time()));
        $noshow_statuses = expregister__get_specific_pstatuses("noshow");
        $query = "SELECT date_format(s.session_start*100,'%Y%m') as sessionmonth,\n                pstatus_id, count(p.participate_id) as num\n                FROM " . table('participate_at') . " as p, " . table('sessions') . " as s\n                WHERE p.session_id>0\n                AND p.session_id=s.session_id\n                AND s.session_status IN ('completed','balanced')\n                AND s.session_start>" . $first_month . " " . $pid_condition . "\n                GROUP BY sessionmonth, pstatus_id\n                ORDER BY sessionmonth, pstatus_id ";
        $result = or_query($query, $pars);
        $noshowperc_data = array();
        while ($line = pdo_fetch_assoc($result)) {
            $counts['bymonth_pstatus_' . $line['pstatus_id']][$line['sessionmonth']] = $line['num'];
            if (!isset($noshowperc_data[$line['sessionmonth']]['n'])) {
                $noshowperc_data[$line['sessionmonth']]['n'] = 0;
            }
            if (!isset($noshowperc_data[$line['sessionmonth']]['y'])) {
                $noshowperc_data[$line['sessionmonth']]['y'] = 0;
            }
            if (in_array($line['pstatus_id'], $noshow_statuses)) {
                $noshowperc_data[$line['sessionmonth']]['n'] += $line['num'];
            } else {
                $noshowperc_data[$line['sessionmonth']]['y'] += $line['num'];
            }
        }
        // get the noshow percentages as well
        foreach ($noshowperc_data as $month => $shownup) {
            $counts['bymonth_noshowrate'][$month] = round($shownup['n'] / ($shownup['n'] + $shownup['y']) * 100, 1);
        }
    }
    $xnames = array('number_reg' => lang('experience'), 'number_noshowup' => lang('noshowup'), 'pstatus' => lang('month'), 'experience_avg_experimentclass' => lang('experiment_classes'), 'experience_avg_pstatus' => lang('participation_status'));
    $titles = array('number_reg' => lang('experience'), 'number_noshowup' => lang('noshows_by_count'), 'last_enrolment' => lang('last_enrolment'), 'last_profile_update' => lang('last_profile_update'), 'last_activity' => lang('last_activity'), 'bymonth_noshowrate' => lang('noshows_by_month'), 'experience_avg_experimentclass' => lang('experience_in_experiment_classes'), 'experience_avg_pstatus' => lang('average_participation_experience'));
    // prepare all-containing arrray to return
    $data_temparray = array();
    foreach ($counts as $c => $nums) {
        $d = array();
        $d['N'] = $count_pids;
        if (isset($pform_types[$c])) {
            $d['browsable'] = true;
            $d['charttype'] = $pform_types[$c]['include_in_statistics'];
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = lang($pform_types[$c]['name_lang']);
            $d['title'] = lang($pform_types[$c]['name_lang']);
            if (preg_match("/(select_lang|radioline_lang)/", $pform_types[$c]['type'])) {
                $d['value_names'] = lang__load_lang_cat($c, lang('lang'));
            } elseif (preg_match("/(radioline|select_list)/", $pform_types[$c]['type'])) {
                $optionvalues = explode(",", $pform_types[$c]['option_values']);
                $optionnames = explode(",", $pform_types[$c]['option_values_lang']);
                $d['value_names'] = array();
                foreach ($optionvalues as $k => $v) {
                    if (isset($optionnames[$k])) {
                        $d['value_names'][$v] = lang($optionnames[$k]);
                    }
                }
            } else {
                $d['value_names'] = array();
            }
            // select numbers?
            if ($pform_types[$c]['type'] == 'select_numbers') {
                krsort($nums);
            } else {
                arsort($nums);
            }
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif (in_array($c, array('number_reg', 'number_noshowup'))) {
            $d['browsable'] = true;
            $d['charttype'] = 'bars';
            if ($c == 'number_reg') {
                $d['wide'] = true;
            }
            $d['limit_not_apply'] = true;
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = $xnames[$c];
            $d['title'] = $titles[$c];
            $d['value_names'] = array();
            krsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif (in_array($c, array('experience_avg_experimentclass', 'experience_avg_pstatus'))) {
            $d['charttype'] = 'pie';
            $d['type_of_data'] = 'calc';
            $d['yname'] = lang('average_count');
            $d['xname'] = $xnames[$c];
            $d['title'] = $titles[$c];
            $d['value_names'] = array();
            if ($c == 'experience_avg_experimentclass') {
                $d['value_names'] = experiment__load_experimentclassnames();
            } else {
                $pstatuses = expregister__get_participation_statuses();
                foreach ($pstatuses as $k => $s) {
                    $d['value_names'][$k] = $s['internal_name'];
                }
            }
            arsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif ($c == 'rules_signed') {
            $d['browsable'] = true;
            $d['charttype'] = 'pie';
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = lang('rules_signed');
            $d['title'] = lang('rules_signed');
            $d['value_names'] = array('n' => lang('n'), 'y' => lang('y'));
            arsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif ($c == 'subpool_id') {
            $d['browsable'] = true;
            $d['charttype'] = 'pie';
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = lang('subpool');
            $d['title'] = lang('subpool');
            $subpools = subpools__get_subpools();
            $d['value_names'] = array();
            foreach ($subpools as $k => $p) {
                $d['value_names'][$k] = $p['subpool_name'];
            }
            arsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif ($c == 'status_id') {
            $d['browsable'] = true;
            $d['charttype'] = 'pie';
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = lang('participant_status');
            $d['title'] = lang('participant_statuses');
            $statuses = participant_status__get_statuses();
            $d['value_names'] = array();
            foreach ($statuses as $k => $p) {
                $d['value_names'][$k] = $p['name'];
            }
            krsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif ($c == 'subscriptions') {
            $d['browsable'] = true;
            $d['charttype'] = 'none';
            $d['type_of_data'] = 'count';
            $d['yname'] = lang('count');
            $d['xname'] = lang('subscriptions');
            $d['title'] = lang('subscriptions');
            $exptypes = load_external_experiment_types("", false);
            $d['value_names'] = array();
            foreach ($exptypes as $k => $p) {
                $d['value_names'][$k] = $p[lang('lang')];
            }
            krsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif (in_array($c, array('last_enrolment', 'last_profile_update', 'last_activity', 'bymonth_noshowrate'))) {
            $d['charttype'] = 'bars';
            $d['wide'] = true;
            if ($c == 'bymonth_noshowrate') {
                $d['yname'] = lang('share_in_percent');
                $d['type_of_data'] = 'calc';
            } else {
                $d['yname'] = lang('count');
                $d['type_of_data'] = 'count';
            }
            $d['xname'] = lang('month');
            $d['title'] = $titles[$c];
            foreach ($nums as $k => $number) {
                if ($k == '-') {
                    $d['value_names'][$k] = $k;
                } else {
                    $d['value_names'][$k] = substr($k, 4, 2) . '/' . substr($k, 2, 2);
                }
            }
            krsort($nums);
            $d['data'] = $nums;
            $data_temparray[$c] = $d;
        } elseif (preg_match('/^bymonth_pstatus/', $c)) {
            $tarr = explode("_", $c);
            $status = $tarr[2];
            if (!isset($data_temparray['bymonth_pstatus'])) {
                $pstatuses = expregister__get_participation_statuses();
                $d['charttype'] = 'multibars';
                $d['wide'] = true;
                $d['type_of_data'] = 'count';
                $d['yname'] = lang('count');
                $d['xname'] = lang('month');
                $d['title'] = lang('participation_status_count_by_month');
                $d['value_names'] = array();
                $d['column_names'] = array();
                foreach ($pstatuses as $k => $s) {
                    $d['column_names'][$k] = $s['internal_name'];
                }
                $data_temparray['bymonth_pstatus'] = $d;
            }
            krsort($nums);
            $data_temparray['bymonth_pstatus']['data'][$status] = $nums;
            $d['value_names'] = array();
            foreach ($data_temparray['bymonth_pstatus']['data'] as $status => $months) {
                foreach ($months as $month => $count) {
                    $d['value_names'][$month] = $month;
                }
            }
            krsort($d['value_names']);
            foreach ($d['value_names'] as $k => $v) {
                $d['value_names'][$k] = substr($v, 4, 2) . '/' . substr($v, 2, 2);
            }
            $data_temparray['bymonth_pstatus']['value_names'] = $d['value_names'];
        }
    }
    // prepare all-containing array to return
    $data_array = array();
    foreach ($statfields as $c) {
        if (isset($data_temparray[$c]['data'])) {
            $data_temparray[$c]['name'] = $c;
            $data_array[$c] = $data_temparray[$c];
        } else {
            $data_array[$c] = array('name' => $c, 'N' => 0, 'data' => array());
        }
    }
    return $data_array;
}
Esempio n. 4
0
function participant__load_participant_email_fields($tlang = '')
{
    global $lang;
    if (!$tlang) {
        $tlang = lang('lang');
    }
    $formfields = participantform__load();
    $result_columns = array();
    foreach ($formfields as $f) {
        if ($f['admin_only'] != 'y') {
            $f['column_name'] = load_language_symbol($f['name_lang'], $tlang);
            if (!$f['column_name']) {
                $f['column_name'] = $f['name_lang'];
            }
            if (preg_match("/(radioline|select_list)/", $f['type'])) {
                $optionvalues = explode(",", $f['option_values']);
                $optionnames = explode(",", $f['option_values_lang']);
                $f['lang'] = array();
                foreach ($optionvalues as $k => $v) {
                    if (isset($optionnames[$k])) {
                        if ($tlang != lang('lang')) {
                            $oname = load_language_symbol($optionnames[$k], $tlang);
                            if ($oname) {
                                $f['lang'][$v] = $oname;
                            } else {
                                $f['lang'][$v] = $optionnames[$k];
                            }
                        } else {
                            if (isset($lang[$optionnames[$k]])) {
                                $f['lang'][$v] = $lang[$optionnames[$k]];
                            } else {
                                $f['lang'][$v] = $optionnames[$k];
                            }
                        }
                    }
                }
            } elseif (preg_match("/(select_lang|radioline_lang)/", $f['type'])) {
                $f['lang'] = lang__load_lang_cat($f['mysql_column_name'], $tlang);
            }
            $result_columns[] = $f;
        }
    }
    return $result_columns;
}