*  for details visit: https://creativecommons.org/licenses/by-sa/3.0/
 *  
 * @Contributors:
 * Created by AvikB for noncommercial MusicBee project.
 *  Spelling mistakes and fixes from community members.
 *
 */
$no_guests = true;
//kick off the guests
require_once $_SERVER['DOCUMENT_ROOT'] . '/functions.php';
include $link['root'] . 'classes/Dashboard.php';
$dashboard = new Dashboard();
$stat['total_download'] = $dashboard->getAddonDownloadCount($mb['user']['id']);
$stat['total_likes'] = $dashboard->getAddonLikeCount($mb['user']['id']);
$stat['total_addon_submitted'] = $dashboard->getAllAddonByMember($mb['user']['id']);
$stat['total_unapproved_addon'] = $dashboard->getAllAddonCountByStatusAndMember($mb['user']['id'], 0);
$stat['top_voted_addon'] = $dashboard->getTopVotedAddonsByAuthor($mb['user']['id'], 10);
$stat['top_downloaded_addon'] = $dashboard->getMostDownloadedAddonsByAuthor($mb['user']['id'], 10);
$stat['unapproved_addons'] = array_slice($dashboard->getAllUnApprovedAddons(), 0, 10);
?>

<div
	class="main_content_wrapper col_1_2">
	<div class="sub_content_wrapper">
		<div class="box_content">
			<span
				class="show_info custom">
				<h3><?php 
echo $lang['dashboard_5'];
?>
</h3>
 //If Add-on submission is turned of show error
 if (!$setting['addonSubmissionOn']) {
     die('{"status": "0", "data": "' . $lang['dashboard_err_20'] . '"}');
 }
 //If user already reached maximum submission limit/day show error
 if (!canUserSubmitAnymoreToday()) {
     die('{"status": "0", "data": "' . $lang['dashboard_err_22'] . '"}');
 }
 //if all user input is ok then move on
 if (validateInput()) {
     $dashboard = new Dashboard();
     //check if an addon with similer name exists or not
     if (!$dashboard->addonExists($_POST['title'], null)) {
         //die, if the user alreay submitted more than X numbers of addon that needed aproval!
         //This will prevent the floodgate
         if ($dashboard->getAllAddonCountByStatusAndMember($mb['user']['id'], 0) > $setting['maxSubmitWithOutApproval']) {
             die('{"status": "0", "data": "' . $lang['dashboard_err_10'] . '"}');
         }
         $readme = isset($_POST['readme']) ? $_POST['readme'] : "";
         //load parsedown for markdown to html converter
         $ParsedownExtra = new ParsedownExtra();
         $ParsedownExtra->setBreaksEnabled(true);
         $readme_raw = $ParsedownExtra->text($readme);
         //load and use html purifier for the readme notes.
         $readme_html = Format::htmlSafeOutput($readme_raw);
         //purify the readme note html
         //Phew.... all validations complete, now SUBMIT THE ADDON!
         if ($dashboard->submit($readme_html, "submit")) {
             //@todo: Add an item to mail queue, and send it to admin
             exit('{"status": "1", "data": "' . $lang['dashboard_msg_11'] . '", "callback_function": "submitted"}');
         }