' . __('Update to','teachpress') . ' ' . $version . '.', 'orange' );
echo $after;
}
}
else {
echo $before;
get_tp_message( '' . __('Install database','teachpress') . '', 'orange' );
echo $after;
}
}
/**
* Extracts checkbox data for meta data fields and returns an array with the saved values.
*
* A string for checkbox data has the following structure:
* {value1},{value2},{value3}
*
* @param string $input
* @return array
* @since 5.0.0
*/
public static function extract_checkbox_data($input) {
$values = array();
$array_values = explode(',', $input);
foreach( $array_values as $element ) {
$element = str_replace(array('{','}'), array('',''), $element);
array_push($values, $element);
}
return $values;
}
/**
* Returns a select field for assessment types
* @param string $field_name The name of the field
* @param string $value The value of the field
* @param string $tabindex The tabindex number
* @return string
* @since 5.0.0
*/
public static function get_assessment_type_field($field_name, $value, $tabindex = ''){
$return = '';
$return .= '';
return $return;
}
/**
* Returns a select field for assessment_passed
* @param string $field_name The name of the field
* @param string $value the value of the field
* @param string $tabindex The tabindex number
* @return string
*/
public static function get_assessment_passed_field($field_name, $value, $tabindex = '') {
$return = '';
$return .= '';
return $return;
}
/**
* Returns checkbox fields for admin form
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $checked value for the field
* @param boolean $readonly true or false, default is false
* @param boolean $required true or false, default is false
* @return string
* @since 5.0.0
*/
public static function get_checkbox_field ($field_name, $label, $checked, $readonly = false, $required = false) {
global $wpdb;
$return = '';
$options = $wpdb->get_results("SELECT * FROM " . TEACHPRESS_SETTINGS . " WHERE `category` = '" . esc_sql($field_name) . "' ORDER BY value ASC");
$ro = ( $readonly === true ) ? 'readonly="true" ' : '' ;
$rq = ( $required === true ) ? 'required="required"' : '';
// extrakt checkbox_values
$array_checked = self::extract_checkbox_data($checked);
$return .= '
';
$i = 1;
$max = count($options);
foreach ($options as $opt) {
$checked = ( in_array($opt->value, $array_checked) ) ? 'checked="checked"' : '';
$rq = ( $max === 1 ) ? $rq : ''; // The required option is only available for single checkboxes
$return .= ' ';
$i++;
}
return $return;
}
/**
* Returns date select fields for admin form
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $value value for the field
* @return string
* @since 5.0.0
*/
public static function get_date_field ($field_name, $label, $value) {
if ( $value != '' ) {
$b = tp_datesplit($value);
}
$day = ( $value != '' ) ? $b[0][2] : '01';
$month = ( $value != '' ) ? $b[0][1] : '01';
$year = ( $value != '' ) ? $b[0][0] : '19xx';
$months = array (
__('Jan','teachpress'),
__('Feb','teachpress'),
__('Mar','teachpress'),
__('Apr','teachpress'),
__('May','teachpress'),
__('Jun','teachpress'),
__('Jul','teachpress'),
__('Aug','teachpress'),
__('Sep','teachpress'),
__('Oct','teachpress'),
__('Nov','teachpress'),
__('Dec','teachpress') );
$return = '';
$return .= '
' . stripslashes($label) . '
';
$return .= '';
$return .= '';
$return .= '';
return $return;
}
/**
* Returns a number field for admin form
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param int $value value for the field
* @param int $min default is 0
* @param int $max default is 999
* @param int $step default is 1
* @param boolean $readonly true or false, default is false
* @param boolean $required true or false, default is false
* @return string
* @since 5.0.0
*/
public static function get_int_field($field_name, $label, $value, $min = 0, $max = 999, $step = 1, $readonly = false, $required = false){
$ro = ( $readonly === true ) ? 'readonly="true" ' : '' ;
$r = ( $required === true ) ? 'required="required"' : '';
return '
';
}
/**
* Returns radio fields for admin form
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $value current value for the field
* @param boolean $readonly true or false, default is false
* @param boolean $required true or false, default is false
* @return string
* @since 5.0.0
*/
public static function get_radio_field ($field_name, $label, $value, $readonly = false, $required = false) {
global $wpdb;
$return = '';
$options = $wpdb->get_results("SELECT * FROM " . TEACHPRESS_SETTINGS . " WHERE `category` = '" . esc_sql($field_name) . "' ORDER BY value ASC");
$ro = ( $readonly === true ) ? 'readonly="true" ' : '' ;
$rq = ( $required === true ) ? 'required="required"' : '';
$return .= '';
$i = 1;
foreach ($options as $opt) {
$checked = ( $value == $opt->value ) ? 'checked="checked"' : '';
$return .= ' ';
$i++;
}
return $return;
}
/**
* Returns a select field for admin/settings screens
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $value value for the field
* @return string
* @since 5.0.0
*/
public static function get_select_field ($field_name, $label, $value) {
global $wpdb;
$return = '';
$return .= '';
$return .= '';
return $return;
}
/**
* Returns a single option for a select field
* @param string $value The option value
* @param string $label The option label
* @param string $match If $match is the same as $value the option is set as selected
* @return string
* @since 7.1.0
*/
public static function get_select_option($value, $label, $match) {
$s = ( $match == $value ) ? 'selected="selected"' : '';
return '';
}
/**
* Returns a text field for admin/settings screens
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $value value for the field
* @param boolean $readonly
* @return string
* @since 5.0.0
*/
public static function get_text_field($field_name, $label, $value, $readonly = false) {
$ro = ( $readonly === false ) ? '' : 'readonly="true" ';
return '
';
}
/**
* Returns a textarea field for admin/settings screens
* @param string $field_name name/id of the field
* @param string $label label for the field
* @param string $value value for the field
* @return string
* @since 5.0.0
*/
public static function get_textarea_field ($field_name, $label, $value) {
return '
';
}
/**
* Returns a form field for the add_publication_page()
* @param array $atts {
* @type string $name field name
* @type string $title field title
* @type string $label field label
* @type string $field_type field type (textarea|input)
* @type string $field_value field value of the current/visible entry
* @type int $tabindex the tab index
* @type string $display defines if the field is visible or not (block|none)
* @type string $style css style attributes
* @type string $container_misc used for custom attributes of the enclosing div container
* }
* @return string
* @since 5.0.0
* @version 2
*/
public static function get_form_field ($atts) {
$param = shortcode_atts(array(
'name' => '',
'title' => '',
'label' => '',
'type' => '',
'value' => '',
'tabindex' => '',
'display' => 'block',
'style' => ''
), $atts);
if ( $param['type'] === 'textarea' ) {
$field = '';
}
else {
$field = '';
}
$a = '
' . $field . '
';
return $a;
}
/**
* Returns a checkbox for admin/settings screens
* @param string $name The field name of the checkbox
* @param string $label The label text for the checkbox
* @param string $value The checkbox value
* @param description A text which is displayed as hover over the label text
* @param boolean $disabled
* @return string
* @since 5.0.0
* @version 2
*/
public static function get_checkbox($name, $label, $value, $description = '', $disabled = false) {
$checked = ( $value == '1' ) ? 'checked="checked"' : '';
$dis = ( $disabled === true ) ? ' disabled="disabled"' : '';
$descr = ( $description != '' ) ? 'title="' . $description . '"' : '';
return ' ';
}
/**
* Displays a box for editing some options (terms|type|studies) for courses
* @param string $title
* @param string $type
* @param array $options (element_title|add_title|delete_title|count_title|tab)
* @since 5.0.0
*/
public static function get_course_option_box ( $title, $type, $options = array() ) {
global $wpdb;
echo '
';
echo '';
echo '';
if ( $type === 'term' ) {
$sql = "SELECT number, value, setting_id FROM ( SELECT COUNT(v.semester) as number, e.variable AS value, e.setting_id as setting_id, e.category as category FROM " . TEACHPRESS_SETTINGS . " e LEFT JOIN " . TEACHPRESS_COURSES . " v ON e.variable = v.semester GROUP BY e.variable ORDER BY number DESC ) AS temp WHERE category = 'semester' ORDER BY setting_id";
}
elseif ( $type === 'type' ) {
$sql = "SELECT number, value, setting_id FROM ( SELECT COUNT(v.type) as number, e.value AS value, e.setting_id as setting_id, e.category as category FROM " . TEACHPRESS_SETTINGS . " e LEFT JOIN " . TEACHPRESS_COURSES . " v ON e.value = v.type GROUP BY e.value ORDER BY number DESC ) AS temp WHERE category = 'course_type' ORDER BY value";
}
elseif ( $type === 'course_of_studies' ) {
$sql = "SELECT number, value, setting_id FROM ( SELECT COUNT(m.meta_value) as number, e.value AS value, e.setting_id as setting_id, e.category as category FROM " . TEACHPRESS_SETTINGS . " e LEFT JOIN " . TEACHPRESS_STUD_META . " m ON e.value = m.meta_value GROUP BY e.value ORDER BY number DESC ) AS temp WHERE category = 'course_of_studies' ORDER BY value";
}
else {
$sql = "SELECT * FROM " . TEACHPRESS_SETTINGS . " WHERE `category` = '" . esc_sql($type) . "' ORDER BY value ASC";
}
$row = $wpdb->get_results($sql);
$class_alternate = true;
foreach ($row as $row) {
if ( $class_alternate === true ) {
$tr_class = 'class="alternate"';
$class_alternate = false;
}
else {
$tr_class = '';
$class_alternate = true;
}
echo '