Exemple #1
0
function do_delete()
{
    global $delete, $conn, $modul;
    if ($delete) {
        preg_match("/(.*)_(.*)/i", $modul, $alter_modul);
        if (isset($alter_modul[2])) {
            if ($alter_modul[2] == 'fields') {
                $sql = "SELECT title, c_default FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE id='" . $delete . "' ";
                $result = db_mysql_query($sql, $conn);
                $arr = db_mysql_fetch_array($result);
                if ($arr['c_default'] == '1') {
                    unset($delete);
                } else {
                    $sql = "ALTER TABLE " . $_SESSION['TABLE_PREFIX'] . $alter_modul[1] . " \n\t\t\t\t\t\t\t\t\tDROP COLUMN " . $arr['title'] . " ";
                    db_mysql_query($sql, $conn);
                }
            }
            if ($alter_modul[2] == 'tree') {
                $data = array();
                $sql = "SELECT id, title, id_parent, sort_order FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE c_active = '1' ORDER BY sort_order ASC ";
                $result = db_mysql_query($sql, $conn);
                while ($arr = db_mysql_fetch_array($result)) {
                    $data[$arr['id']] = $arr;
                }
                delete_tree($alter_modul[1], build_tree($data, $delete), $delete);
                $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $alter_modul[1] . " WHERE id_tree = '" . $delete . "' ";
                db_mysql_query($sql, $conn);
            }
        }
        if (isset($delete)) {
            $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE id = '" . $delete . "' ";
            db_mysql_query($sql, $conn);
        }
    }
}
function update_order($order, $id)
{
    global $conn, $modul;
    if ($id) {
        $sql = "SELECT id, sort_order FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE sort_order = '" . $order . "' AND id != '" . $id . "' LIMIT 1 ";
        $result = db_mysql_query($sql, $conn);
        if (db_mysql_num_rows($result)) {
            $arr = db_mysql_fetch_array($result);
            $order++;
            $sql_upd = "UPDATE " . $_SESSION['TABLE_PREFIX'] . $modul . " SET sort_order = '" . $order . "' WHERE id = '" . $arr['id'] . "' ";
            db_mysql_query($sql_upd, $conn);
            update_order($order, $arr['id']);
        }
    }
}
Exemple #3
0
function print_chart($params, $line, $option = NULL, $select = 0)
{
    global $conn;
    $height = 300;
    $chart_height = 360;
    $max_width = 800;
    $chart_width = 900;
    if (!isset($params['FILTER'])) {
        $params['FILTER'] = NULL;
    } elseif (!isset($params['SORT'])) {
        $params['SORT'] = NULL;
    }
    if (!isset($params['GROUP'])) {
        $params['GROUP'] = NULL;
    }
    if (!isset($params['ADD'])) {
        $params['ADD'] = NULL;
    }
    $result = db_mysql_query(select_tbody($params['TABLE'], $params['SORT'], $params['FILTER'], $params['GROUP'], $params['ADD']), $conn);
    $max = 0;
    $base_arr = array();
    $count = db_mysql_num_rows($result);
    while ($arr = db_mysql_fetch_array($result)) {
        if ($arr[$line['VAL']] >= $max) {
            $max = $arr[$line['VAL']];
        }
        if ($line['DATA'] == 'date') {
            $date = explode('-', $arr['datefromto']);
            if ($option == 'hour') {
                array_push($base_arr, date('H', $date[0]));
                $data_arr[$arr[$line['KEY']]][date('H', $date[0])] = $arr[$line['VAL']];
                if ($count == 1) {
                    array_unshift($base_arr, date('H', strtotime('-1 hour', $date[0])));
                    array_push($base_arr, date('H', strtotime('+1 hour', $date[0])));
                }
            }
            if ($option == 'day') {
                array_push($base_arr, date('d.m', $date[0]));
                $data_arr[$arr[$line['KEY']]][date('d.m', $date[0])] = $arr[$line['VAL']];
                if ($count == 1) {
                    array_unshift($base_arr, date('d.m', strtotime('-1 day', $date[0])));
                    array_push($base_arr, date('d.m', strtotime('+1 day', $date[0])));
                }
            }
            if ($option == 'month') {
                array_push($base_arr, date('F', $date[0]));
                $data_arr[$arr[$line['KEY']]][date('F', $date[0])] = $arr[$line['VAL']];
                if ($count == 1) {
                    array_unshift($base_arr, date('F', strtotime('-1 month', $date[0])));
                    array_push($base_arr, date('F', strtotime('+1 month', $date[0])));
                }
            }
            if ($option == 'year') {
                array_push($base_arr, date('Y', $date[0]));
                $data_arr[$arr[$line['KEY']]][date('Y', $date[0])] = $arr[$line['VAL']];
                if ($count == 1) {
                    array_unshift($base_arr, date('Y', strtotime('-1 year', $date[0])));
                    array_push($base_arr, date('Y', strtotime('+1 year', $date[0])));
                }
            }
        } else {
            array_push($base_arr, $arr[$line['DATA']]);
            $data_arr[$arr[$line['KEY']]][$arr[$line['DATA']]] = $arr[$line['VAL']];
        }
    }
    foreach ($data_arr as $key => $value) {
        if (count($value) == 1) {
            array_unshift($data_arr[$key], 0);
            array_push($data_arr[$key], 0);
        }
    }
    print "<div class='chart-wrapper'>";
    print "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' class='chart' aria-labelledby='title' role='img' height='100%' width='100%' viewBox='0 0 " . $chart_width . " " . $chart_height . "'>";
    print base_chart($base_arr, array(floor($max / 2), $max), $height, $max_width, 50);
    if ($select != 0) {
        print data_chart($data_arr[$select], 1, $max, $height, $max_width, 50);
    } else {
        $i = 1;
        foreach ($data_arr as $key => $value) {
            print data_chart($value, $i, $max, $height, $max_width, 50);
            $i++;
        }
    }
    print "</svg>";
    if (count($data_arr) > 1) {
        print "<ul class='legend'>";
        $i = 1;
        foreach ($data_arr as $key => $value) {
            print "<li><div class='color-box color-" . $i . "'></div>" . $key . "</li>";
            $i++;
        }
        print "</ul>";
    }
    print "</div>";
}
                         $sql .= ", ";
                     }
                 }
                 $sql .= ")";
                 db_mysql_query($sql, $conn);
                 if ($action != 'add') {
                     $id = db_last_id($conn);
                 }
             }
         }
         ###### Inhalt aus datenbank auslesen wenn ID gesetzt und Datenaktualisiert wurden ######
         if (isset($id)) {
             $sql = "SELECT * FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE id = '" . $id . "' ";
             $result = db_mysql_query($sql, $conn);
             if (db_mysql_num_rows($result)) {
                 foreach (db_mysql_fetch_array($result) as $key => $val) {
                     ${$key} = $val;
                 }
             }
         }
         $success = true;
     } else {
         foreach ($_POST as $key => $val) {
             ${$key} = $val;
         }
     }
 } else {
     ###### Bei Reload variablen neu befüllen #######
     foreach ($_POST as $key => $val) {
         ${$key} = $val;
     }
 ${$arr['title']} = unserialize(${$arr['title']});
 foreach (${$arr['title']} as $key => $val) {
     ${"c_multi_" . $arr['title'] . "_" . $key} = $val;
 }
 if ($arr['source_table']) {
     if (!isset($arr['value']) or !$arr['value']) {
         $arr['value'] = 'id';
     }
     if (!isset($arr['label']) or !$arr['label']) {
         $arr['label'] = 'title';
     }
     $sql_sub = "SELECT " . $arr['value'] . ", " . $arr['label'] . " FROM " . $_SESSION['TABLE_PREFIX'] . $arr['source_table'] . " WHERE c_active = '1' ";
     $result_sub = db_mysql_query($sql_sub, $conn);
     if (db_mysql_num_rows($result_sub)) {
         $i = 1;
         while ($arr_sub = db_mysql_fetch_array($result_sub)) {
             $formdata['c_multi_' . $arr['title'] . '_' . $arr_sub[$arr['value']]] = array('type' => 'checkbox', 'parent_class' => 'multi_checkbox', 'settings' => array('data' => array($arr_sub[$arr['value']] => $arr_sub[$arr['label']])));
             if ($i == 1) {
                 $formdata['c_multi_' . $arr['title'] . '_' . $arr_sub[$arr['value']]]['label'] = $formdata[$arr['title']]['label'];
                 unset($formdata[$arr['title']]);
                 $i++;
             }
         }
     }
 } else {
     $arr['source_value'] = unserialize($arr['source_value']);
     $i = 1;
     foreach ($arr['source_value'] as $key => $val) {
         $formdata['c_multi_' . $arr['title'] . '_' . $key] = array('type' => 'checkbox', 'parent_class' => 'multi_checkbox', 'settings' => array('data' => array($key => $val)));
         if ($i == 1) {
             $formdata['c_multi_' . $arr['title'] . '_' . $key]['label'] = $formdata[$arr['title']]['label'];
Exemple #6
0
function init($data, $para = "default", $table = NULL)
{
    global $conn, $modul;
    switch ($para) {
        case "add":
            $return_data = init($data, $table);
            break;
        case "number":
            $return_data = number_format($data, 0, ",", ".");
            break;
        case "int":
            $return_data = $data;
            break;
        case "text":
            $return_data = $data;
            break;
        case "activate":
            $return_data = $data;
            break;
        case "duration":
            $hour = floor($data / 3600);
            $min = floor(($data - $hour * 3600) / 60);
            $sec = $data - $hour * 3600 - $min * 60;
            if ($hour < 10) {
                $hour = "0" . $hour;
            }
            if ($min < 10) {
                $min = "0" . $min;
            }
            if ($sec < 10) {
                $sec = "0" . $sec;
            }
            $return_data = $hour . ":" . $min . ":" . $sec;
            break;
        case "datefromto":
            $data = explode('-', $data);
            $return_data = date('d.m.Y - H:i', $data[0]) . " " . v('CMT_TO') . " " . date('d.m.Y - H:i', $data[1]);
            break;
        case "date":
            $return_data = date('d.m.Y - H:i', $data);
            break;
        case "select":
            preg_match("/(.*)_(.*)/i", $modul, $next_modul);
            if ($next_modul) {
                $next_modul = $next_modul[1];
            } else {
                $next_modul = $modul;
            }
            if ($table == 'id_field' or $table == 'id_parent') {
                if ($table == 'id_field') {
                    $table = $next_modul . "_fields";
                }
                if ($table == 'id_parent') {
                    $table = $modul;
                }
                $sql = "SELECT title FROM " . $_SESSION['TABLE_PREFIX'] . $table . " WHERE id='" . $data . "' LIMIT 1";
                $result = db_mysql_query($sql, $conn);
                if (db_mysql_num_rows($result)) {
                    $arr = db_mysql_fetch_array($result);
                    $return_data = $arr['title'];
                } else {
                    $return_data = NULL;
                }
            } else {
                $sql = "SELECT source_table, label FROM " . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields WHERE title='" . $table . "' LIMIT 1";
                $result = db_mysql_query($sql, $conn);
                if (db_mysql_num_rows($result)) {
                    $arr = db_mysql_fetch_array($result);
                    if (!$arr['label']) {
                        $arr['label'] = 'title';
                    }
                    $sql_tmp = "SELECT " . $arr['label'] . " FROM " . $_SESSION['TABLE_PREFIX'] . $arr['source_table'] . " WHERE id='" . $data . "' LIMIT 1";
                    $result_tmp = db_mysql_query($sql_tmp, $conn);
                    if (db_mysql_num_rows($result_tmp)) {
                        $arr_tmp = db_mysql_fetch_array($result_tmp);
                        $return_data = $arr_tmp[$arr['label']];
                    } else {
                        $return_data = NULL;
                    }
                } else {
                    $return_data = NULL;
                }
            }
            break;
        case "textarea":
            $return_data = $data;
            break;
        case "default":
        default:
            if (is_numeric($data)) {
                $return_data = init($data, 'number');
            } else {
                $return_data = $data;
            }
            break;
    }
    return $return_data;
}
    $formdata['update_parent'] = array('type' => 'hidden', 'value' => 1);
}
$formdata['date'] = array('type' => 'datepicker', 'label' => v('CMT_DATE'), 'parent_class' => 'date', 'value' => array('date' => date('d.m.Y', $date), 'time' => date('H:i', $date)));
$formdata['title'] = array('type' => 'text', 'label' => v('CMT_TITLE'), 'style' => array('class' => "col-3_of_7"));
$fieldset = 'none';
if ($fieldset == 'none') {
    $formdata['type'] = array('type' => 'select', 'label' => v('CMT_TYPE'), 'class' => 'reload_select', 'settings' => array('data' => array('int' => v('CMT_TYPE_INTEGER'), 'text' => v('CMT_TYPE_TEXT'), 'textarea' => v('CMT_TYPE_TEXTAREA'), 'datepicker' => v('CMT_TYPE_DATEPICKER'), 'checkbox' => v('CMT_TYPE_CHECKBOX'), 'multicheckbox' => v('CMT_TYPE_MULTICHECKBOX'), 'select' => v('CMT_TYPE_SELECT'), 'multiselect' => v('CMT_TYPE_MULTISELECT'), 'radio' => v('CMT_TYPE_RADIO'))), 'style' => array('class' => "col-3_of_7"));
    if (isset($type)) {
        if ($type == 'multicheckbox' or $type == 'select' or $type == 'multiselect' or $type == 'radio') {
            $formdata['value'] = array('type' => 'text', 'label' => v('CMT_VALUE'), 'style' => array('class' => "col-3_of_7"));
            $formdata['label'] = array('type' => 'text', 'label' => v('CMT_LABEL'), 'style' => array('class' => "col-3_of_7"));
            $formdata['source_table'] = array('type' => 'select', 'label' => v('CMT_DATABASE'), 'settings' => array('data' => array(NULL => NULL)), 'style' => array('class' => "col-3_of_7"));
            $sql = "SHOW TABLES";
            $result = db_mysql_query($sql, $conn);
            if (db_mysql_num_rows($result)) {
                while ($arr = db_mysql_fetch_array($result)) {
                    foreach ($arr as $database) {
                        $formdata['source_table']['settings']['data'][$database] = $database;
                    }
                }
            }
        }
    }
    $formdata['valid_type'] = array('type' => 'select', 'label' => v('CMT_VALID_TYPE'), 'class' => 'reload_select', 'settings' => array('data' => array('none' => v('CMT_VALID_NONE'), 'numeric' => v('CMT_VALID_NUMERIC'), 'min' => v('CMT_VALID_MIN'), 'max' => v('CMT_VALID_MAX'), 'email' => v('CMT_VALID_EMAIL'), 'url' => v('CMT_VALID_URL'), 'regex' => v('CMT_VALID_REGEX'))), 'style' => array('class' => "col-3_of_7"));
    if ($valid_type != 'none' && $valid_type != 'numeric' && $valid_type != 'email' && $valid_type != 'ulr') {
        $formdata['valid_value'] = array('type' => 'text', 'label' => v('CMT_VALID_VALUE'), 'style' => array('class' => "col-3_of_7"));
    }
}
$formdata['c_readonly'] = array('type' => 'checkbox', 'label' => v('CMT_READONLY'));
$formdata['c_required'] = array('type' => 'checkbox', 'label' => v('CMT_REQUIRED'));
$formdata['c_list'] = array('type' => 'checkbox', 'label' => v('CMT_DISPLAY'), 'parent_class' => 'multi_checkbox', 'settings' => array('data' => array('1' => v('CMT_LIST'))));
Exemple #8
0
function select_tbody($params, $order, $filter = NULL, $group_by = NULL, $add = NULL, $limit = NULL)
{
    global $modul, $conn, $sub_page, $pages;
    $i = 0;
    $z = count($params);
    $sql = "SELECT c_active, ";
    if ($modul == 'content_fields') {
        $sql .= "c_default, ";
    }
    if (isset($add)) {
        $sql .= $add . ", ";
    }
    foreach ($params as $key => $value) {
        $i++;
        if ($value != 'add') {
            $sql .= $key;
            if ($i != $z) {
                $sql .= ", ";
            } else {
                $sql .= " ";
            }
        }
    }
    if (!isset($params['id'])) {
        $sql .= ", id ";
    }
    $sql .= "FROM " . $_SESSION['TABLE_PREFIX'] . $modul;
    if (isset($filter)) {
        $sql .= " WHERE ";
        $i = 0;
        foreach ($filter as $key => $value) {
            if ($i > 0) {
                $sql .= "AND ";
            }
            if ($key == 'activate') {
                $sql .= $value;
            } elseif ($key == 'options') {
                $sql .= $value;
            } elseif ($key == 'q') {
                $sql .= "(" . $value . ")";
            } elseif ($key == 'date') {
                $sql .= $key . " BETWEEN '" . $value['from_date'] . "' AND '" . $value['to_date'] . "' ";
            } else {
                $sql .= $key . " = '" . $value . "' ";
            }
            $i++;
        }
    }
    if (isset($group_by)) {
        $sql .= " GROUP BY " . $group_by;
    }
    if (count($order)) {
        $sql .= " ORDER BY ";
        foreach ($order as $key => $value) {
            $sql .= $key . " " . $value;
        }
    }
    if (isset($limit)) {
        $save_sql = $sql;
        $sql = "SELECT count(*) AS number FROM (" . $sql . ") AS number";
        $result = db_mysql_query($sql, $conn);
        $arr_count = db_mysql_fetch_array($result);
        $count = $arr_count['number'];
        $start = $sub_page * $limit - $limit;
        $pages = $count / $limit;
        $sql = $save_sql;
        $sql .= " LIMIT " . $start . ", " . $limit;
    }
    return $sql;
}
Exemple #9
0
function get_field_type($id)
{
    global $conn, $modul;
    preg_match("/(.*)_(.*)/i", $modul, $next_modul);
    if ($next_modul) {
        $next_modul = $next_modul[1];
    } else {
        $next_modul = $modul;
    }
    $sql = "SELECT * FROM " . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields WHERE id = '" . $id . "' ";
    $result = db_mysql_query($sql, $conn);
    if (db_mysql_num_rows($result)) {
        $arr = db_mysql_fetch_array($result);
        return $arr['type'];
    }
}
Exemple #10
0
function cross_table($title, $value = 0, $value_name = NULL, $value_label = NULL)
{
    global $conn, $formdata, $modul;
    preg_match("/(.*)_(.*)/i", $modul, $next_modul);
    if ($next_modul) {
        $next_modul = $next_modul[1];
    } else {
        $next_modul = $modul;
    }
    $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . $formdata[$title]['settings']['data'] . "' AND COLUMN_NAME = 'id_parent' ";
    $result = db_mysql_query($sql, $conn);
    $id_parent = db_mysql_num_rows($result);
    if ($id_parent) {
        $arr_tmp = create_tree($formdata[$title]['settings']['data']);
        generate_tree_select($title, $arr_tmp, tree_get_parents($formdata[$title]['settings']['data'], $value));
        $formdata['levels'] = array('type' => 'hidden', 'value' => 1);
        unset($formdata[$title]);
    } else {
        if ($title == 'language') {
            $next_modul = 'content';
        }
        $sql = "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '" . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields' AND COLUMN_NAME = 'id' ";
        $result = db_mysql_query($sql, $conn);
        if (db_mysql_num_rows($result)) {
            $sql = "SELECT value, label FROM " . $_SESSION['TABLE_PREFIX'] . $next_modul . "_fields WHERE source_table = '" . $formdata[$title]['settings']['data'] . "' ";
            $result = db_mysql_query($sql, $conn);
            if (db_mysql_num_rows($result)) {
                $arr = db_mysql_fetch_array($result);
            }
        }
        if (!isset($arr['value']) or !$arr['value']) {
            $arr['value'] = 'id';
        }
        if (!isset($arr['label']) or !$arr['label']) {
            $arr['label'] = 'title';
        }
        if (isset($value_name) && $value_name) {
            $arr['value'] = $value_name;
        }
        if (isset($value_label) && $value_label) {
            $arr['value'] = $value_label;
        }
        $sql_tmp = "SELECT " . $arr['value'] . ", " . $arr['label'] . ", sort_order FROM " . $formdata[$title]['settings']['data'] . " WHERE c_active = '1' ";
        if ($formdata[$title]['settings']['data'] == 'content_templates') {
            $sql_tmp .= "GROUP BY id_template ";
        }
        $sql_tmp .= "ORDER BY sort_order ASC ";
        $result_tmp = db_mysql_query($sql_tmp, $conn);
        if ($formdata[$title]['settings']['data'] == 'cmt_accounts') {
            $formdata[$title]['value'] = CMT_USER_ID;
        }
        unset($formdata[$title]['settings']['data']);
        if ($formdata[$title]['type'] != 'radio') {
            $formdata[$title]['settings']['data'][0] = "...";
        }
        while ($arr_tmp = db_mysql_fetch_array($result_tmp)) {
            if ($arr['label'] == 'label') {
                $formdata[$title]['settings']['data'][$arr_tmp[$arr['value']]] = v("CMT_" . $arr_tmp[$arr['label']]);
            } else {
                $formdata[$title]['settings']['data'][$arr_tmp[$arr['value']]] = $arr_tmp[$arr['label']];
            }
        }
    }
}