<?php

/*
  PHP version 5
  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220
*/




use admin_application\ArticleModelDB;
use admin_application\AdminPublicDB;
use admin_application\ArticleTypeDB;
use modul_application\ESPCMS_ArticleTypeDB;
use admin_application\link\ArticleLink;

class ArticleSidebar {

	public static function into() {
		$espcms_admin_templates = espcms_admin_template();
		$espcms_admin_templates->libfile = true;
		$lng = AdminPublicDB::get_lancode();
		$mid = espcms_ismatches($_GET['mid']) && !empty($_GET['mid']) ? $_GET['mid'] : 0;
		$tid = espcms_ismatches($_GET['tid']) && !empty($_GET['tid']) ? $_GET['tid'] : 0;
		$article_type_array = ArticleTypeDB::get_article_type_list(0, 0, $mid, false, $lng, true);
		if (is_array($article_type_array) && count($article_type_array) > 0) {
			foreach ($article_type_array as $key => $value) {
				$article_type_array[$key]['pId'] = $value['upid'];
				$article_type_array[$key]['title'] = $value['typename'];
				$article_type_array[$key]['class'] = 'aaa';
				if ($value['linkid']) {
					$id = $value['tid'];
					$name = $value['typename'];
					if ($value['gotoid']) {
						$value['linkid'] = ESPCMS_ArticleTypeDB::get_article_type_view($value['gotoid'], 'linkid');
					}
					$value['did'] = $value['linkid'];
					$url = ArticleLink::Article_Main_link_array('edit', $value);
					$article_type_array[$key]['click'] = "click_espcms_window_tab('$name','$url','espcms_goodstype_tab_$id','glyphicon glyphicon-edit','false')";
				} else {
					$article_type_array[$key]['url'] = espcms_add_self_url(array('tid' => $value['tid'], 'mid' => $mid));
				}
				if ($tid == $value['tid']) {
					$article_type_array[$key]['open'] = 'true';
					$article_type_array[$key]['name'] = "<span class='text-orange strong'>" . $value['typename'] . "</span>";
				} else {
					$article_type_array[$key]['name'] = $value['linkid'] > 0 ? "<span class='strong'>" . $value['typename'] . "</span>" : $value['typename'];
				}
			}
		} else {
			$article_type_array = array();
		}

		$espcms_admin_templates->into('article_type_array', $article_type_array);
		$viewall_title = espcms_ismatches($tid) && !empty($tid) ? espcms_lan_pack('public_pack-espcms_lable_viewall_name') : "<span class='text-orange strong'>" . espcms_lan_pack('public_pack-espcms_lable_viewall_name') . "</span>";
		$viewall_link = espcms_add_self_url(array('tid' => 0, 'mid' => $mid));
		$viewall_array_key[] = array('id' => '', 'pId' => '', 'name' => $viewall_title, 'title' => $viewall_title, 'has_c' => 0, 'level' => 0, 'pathid' => 0, 'parentpath' => 0, 'url' => $viewall_link);
		$new_article_type_array = is_array($article_type_array) ? array_merge($viewall_array_key, $article_type_array) : $viewall_array_key;
		$espcms_admin_templates->into('category_array', $new_article_type_array);
		$espcms_admin_templates->into('category_json', json_encode($new_article_type_array));
		$espcms_admin_templates->into('current_tid', $tid);
		$model_list = ArticleModelDB::get_model_list(0, false, 0);
		if (is_array($model_list)) {
			foreach ($model_list as $key => $value) {
				$model_list[$key]['url'] = espcms_add_self_url(array('tid' => 0, 'mid' => $value['mid']));
			}
		}
		$viewall_mid_link = espcms_add_self_url(array('tid' => 0, 'mid' => 0));
		$viewall_mid_array_key[] = array('mid' => 0, 'modelname' => espcms_lan_pack('public_pack-espcms_lable_viewall_name'), 'url' => $viewall_mid_link);
		$new_model_list_array = array_merge($viewall_mid_array_key, $model_list);
		$espcms_admin_templates->into('model_list', $new_model_list_array);
		$espcms_admin_templates->into('current_mid', $mid);
		$output = $espcms_admin_templates->fetch('article/sidebar_article');
		return $output;
	}

}
