0, "download_cat_parent" => 0, "download_cat_hidden" => [], "download_cat_name" => "", "download_cat_description" => "", "download_cat_language" => LANGUAGE, "download_cat_sort_by" => "", "download_cat_sort_order" => "ASC", ]; if (isset($_POST['save_cat'])) { $data = [ "download_cat_id" => form_sanitizer($_POST['download_cat_id'], "", "download_cat_id"), "download_cat_parent" => form_sanitizer($_POST['download_cat_parent'], "", "download_cat_parent"), "download_cat_hidden" => [], "download_cat_name" => form_sanitizer($_POST['download_cat_name'], "", "download_cat_name"), "download_cat_description" => form_sanitizer($_POST['download_cat_description'], "", "download_cat_description"), "download_cat_language" => form_sanitizer($_POST['download_cat_language'], "", "download_cat_language"), "download_cat_sort_by" => form_sanitizer($_POST['download_cat_sort_by'], "", "download_cat_sort_by"), "download_cat_sort_order" => form_sanitizer($_POST['download_cat_sort_order'], "DESC", "download_cat_sort_order"), ]; switch ($data['download_cat_sort_by']) { case 1: $data['download_cat_sorting'] = "download_id ".($data['download_cat_sort_order'] == "ASC" ? "ASC" : "DESC"); break; case 2: $data['download_cat_sorting'] = "download_title ".($_POST['download_cat_sort_order'] == "ASC" ? "ASC" : "DESC"); break; case 3: $data['download_cat_sorting'] = "download_datestamp ".($_POST['download_cat_sort_order'] == "ASC" ? "ASC" : "DESC"); break; default: $data['download_cat_sorting'] = "download_title ASC"; } // Category Name Check $categoryNameCheck = [ "when_updating" => "download_cat_name='".$data['download_cat_name']."' and download_cat_id !='".$data['download_cat_id']."'", "when_saving" => "download_cat_name='".$data['download_cat_name']."'", ]; if (defender::safe()) { if (dbcount("(download_cat_id)", DB_DOWNLOAD_CATS, "download_cat_id='".$data['download_cat_id']."'")) { if (!dbcount("(download_cat_id)", DB_DOWNLOAD_CATS, $categoryNameCheck['when_updating'])) { dbquery_insert(DB_DOWNLOAD_CATS, $data, "update"); addNotice("success", $locale['download_0151']); redirect(clean_request("cat_view=1", ["section", "aid"], TRUE)); } else { \defender::stop(); addNotice("danger", $locale['download_0352']); } } else { if (!dbcount("(download_cat_id)", DB_DOWNLOAD_CATS, $categoryNameCheck['when_saving'])) { dbquery_insert(DB_DOWNLOAD_CATS, $data, "save"); addNotice("success", $locale['download_0150']); redirect(clean_request("cat_view=1", ["section", "aid"], TRUE)); } else { \defender::stop(); addNotice("danger", $locale['download_0352']); } } } } if ((isset($_GET['action']) && $_GET['action'] == "edit") && (isset($_GET['cat_id']) && isnum($_GET['cat_id']))) { $result = dbquery("SELECT * FROM ".DB_DOWNLOAD_CATS." ".(multilang_table("DL") ? "WHERE ".in_group('download_cat_language', LANGUAGE)." AND" : "WHERE")." download_cat_id='".$_GET['cat_id']."'"); if (dbrows($result)) { $data = dbarray($result); $data['download_cat_hidden'] = [$data['download_cat_id']]; $cat_sorting = explode(" ", $data['download_cat_sorting']); $data['download_cat_sort_by'] = ""; if ($cat_sorting[0] == "download_id") { $data['download_cat_sort_by'] = "1"; } else if ($cat_sorting[0] == "download_title") { $data['download_cat_sort_by'] = "2"; } else if ($cat_sorting[0] == "download_datestamp") { $data['download_cat_sort_by'] = "3"; } $data['download_cat_sort_order'] = $cat_sorting[1]; } else { redirect(clean_request("", ["section", "aid"], TRUE)); } } $tab_cats['title'][] = $locale['download_0023']; $tab_cats['id'][] = "dlcats_form"; $tab_cats['icon'][] = ""; $tab_cats['title'][] = $locale['download_0020']; $tab_cats['id'][] = "dlcats"; $tab_cats['icon'][] = ""; $tab_cats_active = tab_active($tab_cats, isset($_GET['cat_view']) ? 1 : 0); echo opentab($tab_cats, $tab_cats_active, 'dcategory', FALSE, "nav-tabs m-t-10"); echo opentabbody($tab_cats['title'][0], $tab_cats['id'][0], $tab_cats_active); echo openform('addcat', 'post', FUSION_REQUEST, ['class' => 'm-t-20']); echo "
\n"; echo "
\n"; openside(''); echo form_hidden("download_cat_id", "", $data['download_cat_id']); echo form_text('download_cat_name', $locale['download_0300'], $data['download_cat_name'], [ 'required' => TRUE, 'error_text' => $locale['download_0351'] ]); echo form_textarea('download_cat_description', $locale['download_0301'], $data['download_cat_description'], [ 'resize' => 0, 'autosize' => TRUE, ]); echo '
'; echo '
'; echo ''; echo form_select('download_cat_sort_by', '', $data['download_cat_sort_by'], [ 'options' => [ '1' => $locale['download_0303'], '2' => $locale['download_0200'], '3' => $locale['download_0305'] ], 'class' => 'pull-left', 'inner_width' => '200px', 'inline' => TRUE ]); echo '
'; echo ''; echo form_select('download_cat_sort_order', '', $data['download_cat_sort_order'], [ 'options' => ['ASC' => $locale['download_0306'], 'DESC' => $locale['download_0307']], 'inner_width' => '200px', 'inline' => TRUE ]); echo '
'; echo '
'; closeside(); echo "
\n
\n"; openside(''); echo form_select_tree("download_cat_parent", $locale['download_0308'], $data['download_cat_parent'], [ "disable_opts" => $data['download_cat_hidden'], "hide_disabled" => TRUE, 'width' => '100%' ], DB_DOWNLOAD_CATS, "download_cat_name", "download_cat_id", "download_cat_parent"); if (multilang_table("DL")) { echo form_select('download_cat_language[]', $locale['global_ML100'], $data['download_cat_language'], [ 'options' => $language_opts, 'placeholder' => $locale['choose'], 'width' => '100%', 'multiple' => TRUE, 'delimeter' => '.' ]); } else { echo form_hidden('download_cat_language', '', $data['download_cat_language']); } closeside(); echo "
\n
\n"; echo form_button('save_cat', $locale['download_0309'], $locale['download_0309'], ['class' => 'btn-success', 'icon' => 'fa fa-hdd-o']); echo closeform(); echo closetabbody(); echo opentabbody($tab_cats['title'][1], $tab_cats['id'][1], $tab_cats_active); $row_num = 0; echo "
"; showcatlist(); echo "
"; if ($row_num == 0) { echo "
".$locale['download_0251']."
\n"; } echo closetabbody(); echo closetab(); } /** * display download category container * * @param int $parent * @param int $level */ function showcatlist($parent = 0, $level = 0) { global $row_num; $locale = fusion_get_locale(); $result = dbquery(" SELECT d.download_cat_id, d.download_cat_name, d.download_cat_description, count(dl.download_id) 'download_count', dc.download_cat_id 'child_categories' from ".DB_DOWNLOAD_CATS." d left join ".DB_DOWNLOAD_CATS." dc on dc.download_cat_parent=d.download_cat_id left join ".DB_DOWNLOADS." dl on dl.download_cat=d.download_cat_id WHERE d.download_cat_parent='$parent' ".(multilang_table("DL") ? "and ".in_group('d.download_cat_language', LANGUAGE) : "")." group by d.download_cat_id ORDER BY d.download_cat_name "); if (dbrows($result) != 0) { while ($data = dbarray($result)) { echo "
"; echo "
\n"; echo "
\n"; echo "".$locale['edit'].""; echo " ".$locale['delete']."\n"; echo "
\n"; echo "
\n"; echo "".str_repeat("—", $level).$data['download_cat_name'].""; if ($data['download_cat_description']) { echo "
".str_repeat("—", $level)."".fusion_first_words($data['download_cat_description'], 50).""; } echo "
\n"; echo "
\n"; echo "
"; $row_num++; showcatlist($data['download_cat_id'], $level + 1); } } }