[26665] | 1 | <?php |
---|
| 2 | defined('TYPETAGS_PATH') or die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * menu link |
---|
| 6 | */ |
---|
| 7 | function typetags_admin_menu($menu) |
---|
| 8 | { |
---|
| 9 | $menu[] = array( |
---|
[26670] | 10 | 'NAME' => 'Colored Tags', |
---|
[26665] | 11 | 'URL' => TYPETAGS_ADMIN, |
---|
| 12 | ); |
---|
| 13 | return $menu; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * tags page |
---|
| 18 | */ |
---|
| 19 | function typetags_admin() |
---|
| 20 | { |
---|
| 21 | global $template, $page; |
---|
| 22 | |
---|
| 23 | if ($page['page'] != 'tags') |
---|
| 24 | { |
---|
| 25 | return; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | include_once(TYPETAGS_PATH . 'include/functions.inc.php'); |
---|
| 29 | |
---|
| 30 | load_language('plugin.lang', TYPETAGS_PATH); |
---|
| 31 | |
---|
| 32 | // save |
---|
| 33 | if (isset($_POST['typetags_submit'])) |
---|
| 34 | { |
---|
| 35 | if ($_POST['mode'] == 'global') |
---|
| 36 | { |
---|
| 37 | $query = ' |
---|
| 38 | UPDATE ' . TAGS_TABLE . ' |
---|
| 39 | SET id_typetags = ' . ($_POST['tag_color-all']!=-1 ? get_typetag_id($_POST['tag_color-all']) : 'NULL') . ' |
---|
| 40 | WHERE id IN ('.$_POST['edit_list'].') |
---|
| 41 | ;'; |
---|
| 42 | pwg_query($query); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | $updates = $deletes = array(); |
---|
| 47 | |
---|
| 48 | foreach (explode(',', $_POST['edit_list']) as $tag_id) |
---|
| 49 | { |
---|
| 50 | if ($_POST['tag_color-'.$tag_id]!=-1) |
---|
| 51 | { |
---|
| 52 | $updates[] = array( |
---|
| 53 | 'id' => $tag_id, |
---|
| 54 | 'id_typetags' => get_typetag_id($_POST['tag_color-'.$tag_id]), |
---|
| 55 | ); |
---|
| 56 | } |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | $deletes[] = $tag_id; |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | mass_updates( |
---|
| 64 | TAGS_TABLE, |
---|
| 65 | array('primary' => array('id'), 'update' => array('id_typetags')), |
---|
| 66 | $updates |
---|
| 67 | ); |
---|
| 68 | |
---|
| 69 | if (!empty($deletes)) |
---|
| 70 | { |
---|
| 71 | $query = ' |
---|
| 72 | UPDATE ' . TAGS_TABLE . ' |
---|
| 73 | SET id_typetags = NULL |
---|
| 74 | WHERE id IN('. implode(',', $deletes) .') |
---|
| 75 | ;'; |
---|
| 76 | pwg_query($query); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | // enter edit |
---|
| 82 | if (isset($_POST['typetags']) and isset($_POST['tags'])) |
---|
| 83 | { |
---|
| 84 | $template->assign('TYPETAGS_LIST', implode(',', $_POST['tags'])); |
---|
| 85 | |
---|
| 86 | $query = ' |
---|
| 87 | SELECT |
---|
| 88 | t.id, |
---|
| 89 | t.name, |
---|
| 90 | id_typetags, |
---|
| 91 | color |
---|
| 92 | FROM ' . TAGS_TABLE . ' AS t |
---|
| 93 | LEFT JOIN ' . TYPETAGS_TABLE . ' AS tt |
---|
| 94 | ON t.id_typetags = tt.id |
---|
| 95 | WHERE t.id IN ('.implode(',', $_POST['tags']).') |
---|
| 96 | ;'; |
---|
| 97 | $result = pwg_query($query); |
---|
| 98 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 99 | { |
---|
| 100 | $row['color_text'] = get_color_text($row['color']); |
---|
| 101 | $template->append('tags', $row); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | $query = 'SELECT * FROM ' . TYPETAGS_TABLE . ' ORDER BY name;'; |
---|
| 105 | $result = pwg_query($query); |
---|
| 106 | |
---|
| 107 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 108 | { |
---|
| 109 | $row['color_text'] = get_color_text($row['color']); |
---|
| 110 | $template->append('typetags', $row); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | $query = ' |
---|
| 115 | SELECT |
---|
| 116 | t.id, |
---|
| 117 | id_typetags, |
---|
| 118 | color |
---|
| 119 | FROM ' . TAGS_TABLE . ' AS t |
---|
| 120 | LEFT JOIN ' . TYPETAGS_TABLE . ' AS tt |
---|
| 121 | ON t.id_typetags = tt.id |
---|
| 122 | ;'; |
---|
| 123 | $template->assign('tags_color', query2array($query, 'id')); |
---|
| 124 | |
---|
| 125 | $template->assign('TYPETAGS_PATH', TYPETAGS_PATH); |
---|
| 126 | $template->set_prefilter('tags', 'typetags_admin_prefilter'); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | function typetags_admin_prefilter($content) |
---|
| 130 | { |
---|
| 131 | // add button |
---|
| 132 | $search[0] = '<input type="submit" name="delete"'; |
---|
| 133 | $replace[0] = '<input type="submit" name="typetags" value="{\'Set tags color\'|translate}"> ' . $search[0]; |
---|
| 134 | |
---|
| 135 | // add form part |
---|
| 136 | $search[1] = '<form action="{$F_ACTION}" method="post">'; |
---|
| 137 | $replace[1] = $search[1] . file_get_contents(realpath(TYPETAGS_PATH . 'template/tags.tpl')); |
---|
| 138 | |
---|
| 139 | // color on main list |
---|
| 140 | $search[2] = '<input type="checkbox" name="tags[]" value="{$tag.id}"> {$tag.name}'; |
---|
| 141 | $replace[2] = '<input type="checkbox" name="tags[]" value="{$tag.id}"> <span style="color:{$tags_color[$tag.id].color};">{$tag.name}</span>'; |
---|
| 142 | |
---|
| 143 | return str_replace($search, $replace, $content); |
---|
| 144 | } |
---|