'inc-db/triggers/bindings.before', 'after' => 'inc-db/triggers/bindings.after', ); /* }}} */ /* * ezin_admin_bindings_main() */ function ezin_admin_bindings_main($perm_articles, $perm_sections, $perm_authors) /* {{{ */ { global $ezin_sys; global $ezin_cfg; global $ezin_db_handle; $op_list = array( 'article_bind_theme' => strstr($perm_articles, 'a'), 'article_bind_lang' => strstr($perm_articles, 'a'), 'page_bind_lang' => strstr($perm_articles, 'a'), 'section_bind_lang' => strstr($perm_sections, 's'), 'author_bind' => strstr($perm_authors, 't')); $op_change = array( 'article_bind_theme' => strstr($perm_articles, 'A'), 'article_bind_lang' => strstr($perm_articles, 'A'), 'page_bind_lang' => strstr($perm_articles, 'A'), 'section_bind_lang' => strstr($perm_sections, 'S'), 'author_bind' => strstr($perm_authors, 'T')); echo '
',"\n"; if (isset($_POST['article_bind_theme'])) { $type = 'article_bind_theme'; } elseif (isset($_POST['article_bind_lang'])) { $type = 'article_bind_lang'; } elseif (isset($_POST['page_bind_lang'])) { $type = 'page_bind_lang'; } elseif (isset($_POST['section_bind_lang'])) { $type = 'section_bind_lang'; } elseif (isset($_POST['author_bind'])) { $type = 'author_bind'; } else { $action = ''; isset($_POST['bind_remove']) && $action = 'remove'; isset($_POST['bind_create']) && $action = 'create'; $type = (string) @$_POST['type']; if ($op_change[$type] && strlen($type) > 0 && strlen($action) > 0) { // save action goes here ezin_admin_bindings_save($type, $action); } } if (strlen($type) <= 0) { $op_list['article_bind_theme'] && $type = 'article_bind_theme'; is_array($ezin_cfg['languages']) && $op_list['section_bind_lang'] && $type = 'section_bind_lang'; } if (! $op_list[$type]) { require 'inc-html/permdenied.html'; return false; } if (stristr($ezin_cfg['admin_buttons_pos'], 'U')) { ezin_admin_bindings_buttons(is_array($ezin_cfg['languages']), $op_change[$type], $type, $op_list); echo '
',"\n"; } switch ($type) { case 'article_bind_theme': $query = 'SELECT a.title AS name, a.atitle AS name2, a.access_key AS name3,' .' a.id, s.lang, a.bind_theme AS bind FROM ' .$ezin_sys['db']['tables']['articles'].' AS a, ' .$ezin_sys['db']['tables']['sections'].' AS s' .' WHERE a.section_id = s.id' .' ORDER BY IFNULL(bind,0) ASC, a.datetime DESC, a.id ASC'; break; case 'article_bind_lang': $query = 'SELECT a.title AS name, a.atitle AS name2, a.access_key AS name3,' .' a.id, s.lang, a.bind_lang AS bind FROM ' .$ezin_sys['db']['tables']['articles'].' AS a, ' .$ezin_sys['db']['tables']['sections'].' AS s' .' WHERE a.section_id = s.id' .' AND UNIX_TIMESTAMP(datetime) != 0' .' ORDER BY IFNULL(bind,0) ASC, a.datetime DESC, a.id ASC'; break; case 'page_bind_lang': $query = 'SELECT a.title AS name, a.atitle AS name2, a.access_key AS name3,' .' a.id, s.lang, a.bind_lang AS bind FROM ' .$ezin_sys['db']['tables']['articles'].' AS a, ' .$ezin_sys['db']['tables']['sections'].' AS s' .' WHERE a.section_id = s.id' .' AND (datetime IS NULL OR UNIX_TIMESTAMP(datetime) = 0)' .' ORDER BY IFNULL(bind,0) ASC, s.ord ASC, s.id ASC, a.id ASC'; break; case 'section_bind_lang': $query = 'SELECT name, ord, access_key AS name2, link AS name3,' .' id, lang, bind_lang AS bind' .' FROM '.$ezin_sys['db']['tables']['sections'] .' ORDER BY IFNULL(bind,0) ASC, ord ASC, id ASC'; break; case 'author_bind': $query = 'SELECT name, access_key AS name2, template_key AS name3,' .' id, bind' .' FROM '.$ezin_sys['db']['tables']['authors'] .' ORDER BY IFNULL(bind,0) ASC, id ASC'; break; default: return false; } $result = mysqli_query($ezin_db_handle, $query); if ($result == false) { echo 'mysqli_query() error'; echo '
'.htmlspecialchars($query); return false; } echo '',"\n"; if (mysqli_num_rows($result) == 0) { echo ''; } $lang_printing = $type != 'article_bind_theme'; $bind_previous = -1; $i = 0; while (($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) != null) { $name = $row['name']; empty($name) && $name = $row['name2']; empty($name) && $name = $row['name3']; $ord = intval($row['ord']); $bind = intval($row['bind']); $lang = empty($row['lang']) ? '--' : $row['lang']; if ($bind_previous != $bind) { if ($bind_previous != -1) { echo '
No records in database.
',"\n"; echo '',"\n"; } $colspan = 2; $lang_printing && $colspan++; $op_change[$type] && $colspan++; echo '',"\n"; echo '',"\n"; $bind_previous = $bind; } echo ''; if ($op_change[$type]) { echo '',"\n"; } if ($lang_printing) { echo '',"\n"; } echo '',"\n"; echo '',"\n"; echo '',"\n"; $i++; $i &= 1; } echo '
',"\n"; if ($bind) { echo 'Binding ID ',$bind; if ($op_change[$type]) { echo ' '; } } else { echo 'Unbinded'; } echo '
',"\n"; echo ''; echo ' '; echo htmlspecialchars($lang),'  '; echo ''; echo $row['id'],' ',htmlspecialchars($name),'
',"\n"; mysqli_free_result($result); if (stristr($ezin_cfg['admin_buttons_pos'], 'D') || ! stristr($ezin_cfg['admin_buttons_pos'], 'U')) { echo '
',"\n"; ezin_admin_bindings_buttons(is_array($ezin_cfg['languages']), $op_change[$type], $type, $op_list); } echo ''; echo '
',"\n"; return; } /* }}} */ function ezin_admin_bindings_buttons($f_multilng, $f_change, $type, $op_list) /* {{{ */ { echo '',"\n"; echo '',"\n",'
',"\n"; $d = $f_multilng ? '' : ' disabled'; $op_list['section_bind_lang'] && print(' '); $op_list['article_bind_lang'] && print(' '); $op_list['article_bind_lang'] && print(' '); $op_list['author_bind'] && print(' '); $op_list['article_bind_lang'] && print(''); echo '',"\n"; // $f_change = 1; // DEBUG $d = $f_change ? '' : ' disabled'; echo ' '; echo ''; echo '
',"\n"; } /* }}} */ function ezin_admin_bindings_save($type, $action) /* {{{ */ { global $ezin_sys; global $ezin_db_handle; global $ezin_admin_bindings_triggers; $ar_rec = @$_POST['record']; $ar_bind = @$_POST['binding']; is_array($ar_rec) || $ar_rec = array(); is_array($ar_bind) || $ar_bind = array(); for ($i = 0; $i < count($ar_rec); $i++) { if (($ar_rec[$i] = intval($ar_rec[$i])) == 0) unset($ar_rec[$i]); } for ($i = 0; $i < count($ar_bind); $i++) { if (($ar_bind[$i] = intval($ar_bind[$i])) == 0) unset($ar_bind[$i]); } if (count($ar_rec) + count($ar_bind) <= 0) return false; $update_value = 0; $update_field = $type == 'article_bind_theme' ? 'bind_theme' : 'bind_lang'; $update_field = $type == 'author_bind' ? 'bind' : $update_field; $update_table = $type == 'section_bind_lang' ? $ezin_sys['db']['tables']['sections'] : $ezin_sys['db']['tables']['articles']; $update_table = $type == 'author_bind' ? $ezin_sys['db']['tables']['authors'] : $update_table; if ($action == 'create') { if (count($ar_bind) > 0) { sort($ar_bind); $update_value = intval($ar_bind[0]); } if (! $update_value) { //$update_value = "MAX($update_field) + 1"; $query = sprintf('SELECT MAX(IFNULL(%s, 0)) + 1 FROM %s', $update_field, $update_table); if ($result = mysqli_query($ezin_db_handle, $query)) { $row = mysqli_fetch_array($result, MYSQLI_NUM); mysqli_free_result($result); $update_value = $row[0]; } } if (! $update_value) { return false; } } $query = sprintf('UPDATE %s SET %s = %s', $update_table, $update_field, $update_value); $query_add = ''; if (count($ar_rec) > 0) { $query_add .= 'id IN ('.join(', ', $ar_rec).')'; // ) } if (count($ar_bind) > 0) { $query_add != '' && $query_add .=' OR '; $query_add .= $update_field.' IN ('.join(', ', $ar_bind).')'; // ) } $query_add != '' && $query .=' WHERE '.$query_add; if (0) { // DEBUG echo 'type = '.$type.'
'; echo 'action = '.$action.'
'; echo 'update_table = '.$update_table.'
'; echo 'update_field = '.$update_field.'
'; echo 'update_value = '.$update_value.'
'; echo 'query
'.htmlspecialchars($query).'
'; } if (file_exists($ezin_admin_bindings_triggers['before'])) { $trigger_ret = include $ezin_admin_bindings_triggers['before']; if ($trigger_ret == false) { return -1; } } if (mysqli_query($ezin_db_handle, $query) == false) { return false; } if (file_exists($ezin_admin_bindings_triggers['after'])) { $trigger_ret = include $ezin_admin_bindings_triggers['after']; if ($trigger_ret == false) { return false; } } return true; } /* }}} */ /* * main stuff */ $ezin_perm_articles = ''; $ezin_perm_sections = ''; $ezin_perm_authors = ''; ezin_admin_check_full_list_privileges($ezin_user['role_articles']) && $ezin_perm_articles .= 'a'; ezin_admin_check_full_list_privileges($ezin_user['role_sections']) && $ezin_perm_sections .= 's'; ezin_admin_check_full_list_privileges($ezin_user['role_authors']) && $ezin_perm_authors .= 't'; strstr($ezin_perm_articles, 'a') && stristr($ezin_user['role_articles'], 'C') && $ezin_perm_articles .= 'A'; strstr($ezin_perm_sections, 's') && stristr($ezin_user['role_sections'], 'C') && $ezin_perm_sections .= 'S'; strstr($ezin_perm_authors, 't') && stristr($ezin_user['role_authors'], 'C') && $ezin_perm_authors .= 'T'; if (strlen($ezin_perm_articles) > 0 || strlen($ezin_perm_sections) > 0 || strlen($ezin_perm_authors) > 0) { ezin_check_db_handle(); ezin_admin_bindings_main($ezin_perm_articles, $ezin_perm_sections, $ezin_perm_authors); ezin_close_db_connection(); } else { require 'inc-html/permdenied.html'; } /* Modeline for ViM {{{ * vim: set ts=4: * vim600: fdm=marker fdl=0 fdc=0: * }}} */ ?>