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']); } } }
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 .= "'" . $val . "'"; if ($i != $num) { $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) {
$formdata[$arr['title']]['settings']['data'] = array('1' => v('CMT_YES')); } if ($arr['type'] == 'multicheckbox') { ${$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) {
<?php if (isset($structure_install) && $structure_install == true) { $structure = "CREATE TABLE IF NOT EXISTS `cmt_modul` (\n \t`id` int(11) NOT NULL,\n \t`modul` varchar(255) NOT NULL,\n \t`modul_string` varchar(255) NOT NULL,\n \t`sort_order` int(11) NOT NULL,\n \t`c_active` enum('0','1') NOT NULL DEFAULT '0'\n\t) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;"; db_mysql_query($structure, $conn); $indizies = "ALTER TABLE `cmt_modul`\n ADD PRIMARY KEY (`id`);"; db_mysql_query($indizies, $conn); $increment = "ALTER TABLE `cmt_modul`\n MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;"; db_mysql_query($increment, $conn); } if (isset($data_install) && $data_install == true) { $data = "INSERT INTO `cmt_modul` (`id`, `modul`, `modul_string`, `sort_order`, `c_active`) VALUES\n\t(1, 'content', '', 1, '1'),\n\t(2, 'labels', '', 3, '1'),\n\t(3, 'accounts', '', 4, '1'),\n\t(4, 'update', '', 5, '1');"; db_mysql_query($data, $conn); }
session_start(); } if (isset($_POST['toggle_sidebar'])) { $_SESSION['toggle_sidebar'] = $_POST['toggle_sidebar']; } if (isset($_POST['toggle_filter'])) { $_SESSION['toggle_filter'] = $_POST['toggle_filter']; } if (isset($_POST['toggle_val']) && isset($_POST['toggle_type'])) { $_SESSION['toggle_filter_' . $_POST['toggle_type']] = $_POST['toggle_val']; } if (isset($_GET['update_sort_order'])) { $i = 1; foreach ($_POST['sort'] as $value) { $sql = "UPDATE " . $_SESSION['TABLE_PREFIX'] . $_SESSION['modul'] . " SET sort_order = '" . $i . "' WHERE id = '" . $value . "' "; db_mysql_query($sql, $conn); $i++; } } if (isset($_GET['form_inputadd'])) { $i = $_GET['form_inputadd']; $formdata['source_value_' . $i] = array('type' => 'input_add', 'label' => v('CMT_DATA'), 'class' => 'source_input', 'style' => array('class' => "col-3_of_7")); print_form($formdata); unset($formdata); } if (isset($_POST['sub_page'])) { if (isset($_POST['modul'])) { $modul = parse($_POST['modul'], 'string'); } if (isset($_POST['sub_page'])) { $sub_page = parse($_POST['sub_page'], 'int');
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; }
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; }
function sql_to_arr($sql) { $return = array(); $result = db_mysql_query($sql); $i = 0; while ($row = mysql_fetch_array($result)) { $j = 0; foreach ($row as $name => $value) { unset($row[$j++]); } $return[$i] = $row; $i++; } return $return; }
<?php if (isset($structure_install) && $structure_install == true) { $structure = "CREATE TABLE IF NOT EXISTS `content` (\n `id` int(11) NOT NULL,\n `date` int(11) DEFAULT NULL,\n `title` varchar(255) DEFAULT NULL,\n `language` varchar(5) DEFAULT NULL,\n `sort_order` int(11) DEFAULT NULL,\n `c_active` int(11) DEFAULT NULL,\n `id_template` int(11) DEFAULT NULL,\n `id_tree` int(11) DEFAULT NULL\n) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"; db_mysql_query($structure, $conn); $indizies = "ALTER TABLE `content`\n ADD PRIMARY KEY (`id`);"; db_mysql_query($indizies, $conn); $increment = "ALTER TABLE `content`\n MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;"; db_mysql_query($increment, $conn); }
function check_duplicate($val, $key = 'title') { global $conn, $modul, $id, $action; $sql = "SELECT * FROM " . $_SESSION['TABLE_PREFIX'] . $modul . " WHERE " . $key . " = '" . $val . "' "; if ($action != 'copy') { if (isset($id) && $id) { $sql .= "AND id != '" . $id . "' "; } } if (isset($_POST['language']) && $_POST['language']) { $sql .= "AND language = '" . $_POST['language'] . "' "; } $result = db_mysql_query($sql, $conn); if (db_mysql_num_rows($result)) { return true; } else { return false; } }
function delete_tree($table, $data, $i = 1, $id_parent = NULL) { global $conn; foreach ($data as $key => $value) { $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $table . " WHERE id_tree = '" . $value['id'] . "' "; db_mysql_query($sql, $conn); $sql = "DELETE FROM " . $_SESSION['TABLE_PREFIX'] . $table . "_tree WHERE id = '" . $value['id'] . "' "; db_mysql_query($sql, $conn); if ($value['id_parent'] == $id_parent) { $i = 1; } if (isset($value['children'])) { delete_tree($table, $value['children'], $i + 1, $value['id_parent']); } } }