Exemple #1
0
function query__get_query_form_prototypes($hide_modules = array(), $experiment_id = "", $status_query = "")
{
    global $lang, $settings, $all_orsee_query_modules;
    $formfields = participantform__load();
    $orsee_query_modules = $all_orsee_query_modules;
    $protoypes = array();
    foreach ($orsee_query_modules as $module) {
        if (!in_array($module, $hide_modules)) {
            switch ($module) {
                case "brackets":
                    $prototype = array('type' => 'brackets', 'displayname' => lang('query_brackets'), 'field_name_placeholder' => '#brackets#');
                    $content = "";
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "experimentclasses":
                    $prototype = array('type' => 'experimentclasses_multiselect', 'displayname' => lang('query_experiment_class'), 'field_name_placeholder' => '#experiment_class#');
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('participants_participated_expclass') . '<BR>';
                    $content .= experiment__experiment_class_select_field('#experiment_class#_ms_classes', array(), true, array('cols' => 40, 'picker_maxnumcols' => 3));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "experimenters":
                    $prototype = array('type' => 'experimenters_multiselect', 'displayname' => lang('query_experimenters'), 'field_name_placeholder' => '#experimenters#');
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('participants_participated_experimenters') . '<BR>';
                    $content .= experiment__experimenters_select_field("#experimenters#_ms_experimenters", array(), true, array('cols' => 40, 'tag_color' => '#f1c06f', 'picker_color' => '#c58720', 'picker_maxnumcols' => 3));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "experimentsassigned":
                    $prototype = array('type' => 'experimentsassigned_multiselect', 'displayname' => lang('query_experiments_assigned'), 'field_name_placeholder' => '#experiments_assigned#');
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('participants_were_assigned_to') . '<BR>';
                    $content .= experiment__other_experiments_select_field("#experiments_assigned#_ms_experiments", "assigned", $experiment_id, array(), true, array('cols' => 80, 'tag_color' => '#b3ffb3', 'picker_color' => '#00a300', 'picker_maxnumcols' => $settings['query_experiment_list_nr_columns']));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "experimentsparticipated":
                    $prototype = array('type' => 'experimentsparticipated_multiselect', 'displayname' => lang('query_experiments_participated'), 'field_name_placeholder' => '#experiments_participated#');
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('participants_have_participated_on') . '<BR>';
                    $content .= experiment__other_experiments_select_field("#experiments_participated#_ms_experiments", "participated", $experiment_id, array(), true, array('cols' => 80, 'tag_color' => '#a8a8ff', 'picker_color' => '#0000ff', 'picker_maxnumcols' => $settings['query_experiment_list_nr_columns']));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "statusids":
                    $prototype = array('type' => 'statusids_multiselect', 'displayname' => lang('query_participant_status'), 'field_name_placeholder' => '#statusids#');
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('participants_of_status') . ' ';
                    $content .= participant_status__multi_select_field("#statusids#_ms_status", array(), array('cols' => 80, 'tag_color' => '#a8a8ff', 'picker_color' => '#0000ff', 'picker_maxnumcols' => 2));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "pformtextfields":
                    $prototype = array('type' => 'pformtextfields_freetextsearch', 'displayname' => lang('query_participant_form_textfields'), 'field_name_placeholder' => '#participant_form_textfields#');
                    $form_query_fields = array();
                    foreach ($formfields as $f) {
                        if (preg_match("/(textline|textarea)/i", $f['type']) && (!$experiment_id && $f['search_include_in_participant_query'] == 'y' || $experiment_id && $f['search_include_in_experiment_assign_query'] == 'y')) {
                            $tfield = array();
                            $tfield['value'] = $f['mysql_column_name'];
                            $tfield['name'] = lang($f['name_lang']);
                            $form_query_fields[] = $tfield;
                        }
                    }
                    $content = "";
                    $content .= lang('where');
                    $content .= ' <INPUT type="text" size="20" maxlength="100" name="search_string" value="">';
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT">' . lang('not') . '</OPTION>
                        <OPTION value="" SELECTED></OPTION>
					</SELECT> ';
                    $content .= ' ' . lang('in') . ' ';
                    $content .= '<SELECT name="search_field">
       	        	<OPTION value="all" SELECTED>' . lang('any_field') . '</OPTION>';
                    foreach ($form_query_fields as $tf) {
                        $content .= '<OPTION value="' . $tf['value'] . '">' . $tf['name'] . '</OPTION>';
                    }
                    $content .= '</SELECT>';
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "pformselects":
                    $pform_selects = array();
                    foreach ($formfields as $f) {
                        if (!preg_match("/(textline|textarea)/i", $f['type']) && (!$experiment_id && $f['search_include_in_participant_query'] == 'y' || $experiment_id && $f['search_include_in_experiment_assign_query'] == 'y')) {
                            $pform_selects[] = $f['mysql_column_name'];
                        }
                    }
                    // $existing=true;
                    //if ($experiment_id) $show_count=false; else $show_count=true;
                    // needs too much time for queries. So  better:
                    $existing = false;
                    $show_count = false;
                    foreach ($pform_selects as $fieldname) {
                        $f = array();
                        foreach ($formfields as $p) {
                            if ($p['mysql_column_name'] == $fieldname) {
                                $f = $p;
                            }
                        }
                        $f = form__replace_funcs_in_field($f);
                        if (isset($f['mysql_column_name'])) {
                            $fieldname_lang = lang($f['name_lang']);
                            $fname_ph = '#pform_select_' . $fieldname . '#';
                            $prototype = array('type' => 'pform_select_' . $fieldname, 'displayname' => lang('query_participant_form_selectfield') . $fieldname_lang, 'field_name_placeholder' => $fname_ph);
                            $content = "";
                            $content .= lang('where') . ' ' . $fieldname_lang . ' ';
                            if ($f['type'] == 'select_numbers') {
                                $content .= '<select name="sign">
                      <OPTION value="<="><=</OPTION>
					  <OPTION value="=" SELECTED>=</OPTION>
                      <OPTION value=">">></OPTION>
					  </select>';
                            } else {
                                $content .= '<select name="not">
				 	<OPTION value="" SELECTED>=</OPTION>
				 	<OPTION value="NOT">' . lang('not') . ' =</OPTION>
				 	</select> ';
                            }
                            if (preg_match("/(select_lang|radioline_lang)/", $f['type'])) {
                                $content .= language__multiselectfield_item($fieldname, $fieldname, $fname_ph . '_ms_' . $fieldname, array(), "", $existing, $status_query, $show_count, true, array('cols' => 80, 'tag_color' => '#bbbbbb', 'picker_color' => '#444444', 'picker_maxnumcols' => 3));
                                $prototype['type'] = 'pform_multiselect_' . $fieldname;
                            } elseif ($f['type'] == 'select_numbers') {
                                if ($f['values_reverse'] == 'y') {
                                    $reverse = true;
                                } else {
                                    $reverse = false;
                                }
                                $content .= participant__select_numbers($fieldname, 'fieldvalue', '', $f['value_begin'], $f['value_end'], 0, $f['value_step'], $reverse, false, $existing, $status_query, $show_count);
                                $prototype['type'] = 'pform_numberselect_' . $fieldname;
                            } elseif (preg_match("/(select_list|radioline)/i", $f['type']) && !$existing) {
                                $f['value'] = '';
                                $content .= form__render_select_list($f, 'fieldvalue');
                                $prototype['type'] = 'pform_simpleselect_' . $fieldname;
                            } else {
                                $content .= participant__select_existing($fieldname, 'fieldvalue', '', $status_query, $show_count);
                                $prototype['type'] = 'pform_simpleselect_' . $fieldname;
                            }
                            $prototype['content'] = $content;
                            $prototypes[] = $prototype;
                        }
                    }
                    break;
                case "noshows":
                    $prototype = array('type' => 'noshows_numbercompare', 'displayname' => lang('query_noshows'), 'field_name_placeholder' => '#noshows#');
                    $query = "SELECT max(number_noshowup) as maxnoshow FROM " . table('participants');
                    if ($status_query) {
                        $query .= " WHERE " . $status_query;
                    }
                    $line = orsee_query($query);
                    $content = "";
                    $content .= lang('where_nr_noshowups_is') . ' ';
                    $content .= '<select name="sign">
                    	<OPTION value="<=" SELECTED><=</OPTION>
               			<OPTION value=">">></OPTION>
                    	</select> ';
                    $content .= helpers__select_number("count", '0', 0, $line['maxnoshow'], 0);
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "participations":
                    $prototype = array('type' => 'participations_numbercompare', 'displayname' => lang('query_participations'), 'field_name_placeholder' => '#participations#');
                    $query = "SELECT max(number_reg) as maxnumreg FROM " . table('participants');
                    if ($status_query) {
                        $query .= " WHERE " . $status_query;
                    }
                    $line = orsee_query($query);
                    $content = "";
                    $content .= lang('where_nr_participations_is') . ' ';
                    $content .= '<select name="sign">
                    	<OPTION value="<=" SELECTED><=</OPTION>
               			<OPTION value=">">></OPTION>
                    	</select> ';
                    $content .= helpers__select_number("count", '0', 0, $line['maxnumreg'], 0);
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "updaterequest":
                    $prototype = array('type' => 'updaterequest_simpleselect', 'displayname' => lang('query_profile_update_request'), 'field_name_placeholder' => '#updaterequest#');
                    $content = "";
                    $content .= lang('where_profile_update_request_is') . ' ';
                    $content .= '<select name="update_request_status">
					<OPTION value="y">' . lang('active') . '</OPTION>
					<OPTION value="n">' . lang('inactive') . '</OPTION>
                   	</select> ';
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "activity":
                    $prototype = array('type' => 'activity_numbercompare', 'displayname' => lang('query_activity'), 'field_name_placeholder' => '#activity#');
                    $content = lang('where');
                    $content .= '<SELECT name="activity_type">
                        <OPTION value="last_activity" SELECTED>' . lang('last_activity') . '</OPTION>
                        <OPTION value="last_enrolment">' . lang('last_enrolment') . '</OPTION>
                        <OPTION value="last_profile_update">' . lang('last_profile_update') . '</OPTION>
        			    <OPTION value="creation_time">' . lang('creation_time') . '</OPTION>';
                    //$content.='    <OPTION value="deletion_time">'.lang('deletion_time').'</OPTION>';
                    $content .= '</SELECT> ';
                    $content .= '<SELECT name="not">
						<OPTION value="" SELECTED></OPTION>
						<OPTION value="NOT">' . lang('not') . '</OPTION>
					</SELECT> ';
                    $content .= lang('before_date') . ' ';
                    $content .= formhelpers__pick_date('#activity#_dt_activity');
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "randsubset":
                    $prototype = array('type' => 'randsubset_limitnumber', 'displayname' => lang('query_rand_subset'), 'field_name_placeholder' => '#rand_subset#');
                    $query_limit = !isset($_REQUEST['query_limit']) || !$_REQUEST['query_limit'] ? $settings['query_random_subset_default_size'] : $_REQUEST['query_limit'];
                    $content = "";
                    $content .= lang('limit_to_randomly_drawn') . ' ';
                    $content .= '<INPUT type="text" data-elem-name="limit" value="' . $settings['query_random_subset_default_size'] . '" size="5" maxlength="10">';
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
                case "subsubjectpool":
                    $prototype = array('type' => 'subsubjectpool_multiselect', 'displayname' => lang('query_subsubjectpool'), 'field_name_placeholder' => '#subsubjectpool#', 'defaults' => array('#subsubjectpool#_not' => '', '#subsubjectpool#_ms_subpool' => ''));
                    $content = "";
                    $content .= '<SELECT name="not">
                        <OPTION value="NOT" SELECTED>' . lang('without') . '</OPTION>
                        <OPTION value="">' . lang('only') . '</OPTION>
					</SELECT> ';
                    $content .= lang('who_are_in_subjectpool') . ' ';
                    $content .= subpools__multi_select_field("#subsubjectpool#_ms_subpool", array(), array('cols' => 80, 'tag_color' => '#a8a8ff', 'picker_color' => '#0000ff', 'picker_maxnumcols' => 1));
                    $prototype['content'] = $content;
                    $prototypes[] = $prototype;
                    break;
            }
        }
    }
    return $prototypes;
}
Exemple #2
0
function formhelpers__pick_time($field, $selected_time = 0, $minute_steps = 0)
{
    global $settings, $lang;
    if (!$selected_time) {
        $selected_time = ortime__unixtime_to_sesstime();
    }
    if (!$minute_steps) {
        $minute_steps = $settings['session_duration_minute_steps'];
    }
    $tformat = lang('format_datetime_time_no_sec');
    $is_mil_time = is_mil_time($tformat);
    $is_mil_time_str = $is_mil_time ? 'true' : 'false';
    $tformat = str_replace("%a", "", $tformat);
    $minutedivisions = round(60 / $minute_steps);
    if (!($minutedivisions > 1)) {
        $minutedivisions = 4;
    }
    $sda = ortime__sesstime_to_array($selected_time);
    $hour_field = helpers__select_hour($field . "_h", $sda['h'], 0, 23, 1, $is_mil_time);
    $minute_field = helpers__select_number($field . "_i", $sda['i'], 0, 59, 2, $settings['session_duration_minute_steps']);
    $tformat = str_replace("%H", $hour_field, $tformat);
    $tformat = str_replace("%h", $hour_field, $tformat);
    $tformat = str_replace("%i", $minute_field, $tformat);
    $cp = '<i id="' . $field . '_clockpicker" class="fa fa-clock-o fa-lg"></i>';
    $cp .= '<script type="text/javascript">
    $(function() {
    function updateTimeSelects_' . $field . ' (time) {
        console.log(time);
        var cpos = time.indexOf( ":", 0 );
        if(cpos<2) {
            var h = Number(time.substr(0,1));
            var i = Number(time.substr(2,2));
        } else {
            var h = Number(time.substr(0,2));
            var i = Number(time.substr(3,2));
        }
        if (time.indexOf("AM",0)>0) {
            if (h==12) { h=0; }
        }
        if (time.indexOf("PM",0)>0) {
            console.log("pm");
            if (h==12) { h=0; }
            h+=12;
        }
        console.log(h + ":" + i);
        ($("#' . $field . '_h")).val(h);
        ($("#' . $field . '_i")).val(i);
    }

    $("#' . $field . '_clockpicker").clockpick({
    starthour: 8,
    endhour: 20,
    showminutes: true,
    minutedivisions: ' . $minutedivisions . ',
    military: ' . $is_mil_time_str . ',
    event: "click", // click, mouseover, or focus
    layout: "vertical",
    hoursopacity: 1.0,
    minutesopacity: 1.0
    }, updateTimeSelects_' . $field . ');
    });
    </script>
    ';
    $out = trim($tformat) . $cp;
    return $out;
}