/**
 * Show Sales Per Month Graph
 *
 * @access      public
 * @since       1.0 
 * @return      void
*/
function edd_show_monthly_sales_graph($bgcolor = 'white')
{
    ob_start();
    ?>
    <script type="text/javascript">
	    google.load("visualization", "1", {packages:["corechart"]});
		// sales chart
	    google.setOnLoadCallback(drawSalesChart);
	    function drawSalesChart() {
	        var data = new google.visualization.DataTable();
	        data.addColumn('string', '<?php 
    _e("Month", "edd");
    ?>
');
	        data.addColumn('number', '<?php 
    _e("Sales", "edd");
    ?>
');
	        data.addRows([
				<?php 
    $i = 1;
    while ($i <= 12) {
        ?>
					['<?php 
        echo edd_month_num_to_name($i) . ' ' . date("Y");
        ?>
', 
					<?php 
        echo edd_get_sales_by_date($i, date('Y'));
        ?>
,
					],
					<?php 
        $i++;
    }
    ?>
	        ]);

	        var options = {
	          	title: "<?php 
    _e('Sales per month', 'edd');
    ?>
",
				colors:['#a3bcd3'],
				fontSize: 12,
				backgroundColor: '#ffffff'
	        };

	        var chart = new google.visualization.ColumnChart(document.getElementById('monthly_sales_chart_div'));
	        chart.draw(data, options);
	    }
    </script>	    
	<div id="monthly_sales_chart_div"></div>
	<?php 
    echo ob_get_clean();
}
 /**
  * Renders an HTML Dropdown of months
  *
  * @access public
  * @since 1.5.2
  * @param string $name Name attribute of the dropdown
  * @param int    $selected Month to select automatically
  * @return string $output Month dropdown
  */
 public function month_dropdown($name = 'month', $selected = 0)
 {
     $month = 1;
     $options = array();
     $selected = empty($selected) ? date('n') : $selected;
     while ($month <= 12) {
         $options[absint($month)] = edd_month_num_to_name($month);
         $month++;
     }
     $output = $this->select(array('name' => $name, 'selected' => $selected, 'options' => $options, 'show_option_all' => false, 'show_option_none' => false));
     return $output;
 }
/**
 * Show report graph date filters
 *
 * @since 1.3
 * @return void
*/
function edd_reports_graph_controls()
{
    $date_options = apply_filters('edd_report_date_options', array('today' => __('Today', 'easy-digital-downloads'), 'yesterday' => __('Yesterday', 'easy-digital-downloads'), 'this_week' => __('This Week', 'easy-digital-downloads'), 'last_week' => __('Last Week', 'easy-digital-downloads'), 'this_month' => __('This Month', 'easy-digital-downloads'), 'last_month' => __('Last Month', 'easy-digital-downloads'), 'this_quarter' => __('This Quarter', 'easy-digital-downloads'), 'last_quarter' => __('Last Quarter', 'easy-digital-downloads'), 'this_year' => __('This Year', 'easy-digital-downloads'), 'last_year' => __('Last Year', 'easy-digital-downloads'), 'other' => __('Custom', 'easy-digital-downloads')));
    $dates = edd_get_report_dates();
    $display = $dates['range'] == 'other' ? '' : 'style="display:none;"';
    $view = edd_get_reporting_view();
    $taxes = !empty($_GET['exclude_taxes']) ? false : true;
    if (empty($dates['day_end'])) {
        $dates['day_end'] = cal_days_in_month(CAL_GREGORIAN, date('n'), date('Y'));
    }
    ?>
	<form id="edd-graphs-filter" method="get">
		<div class="tablenav top">
			<div class="alignleft actions">

				<input type="hidden" name="post_type" value="download"/>
				<input type="hidden" name="page" value="edd-reports"/>
				<input type="hidden" name="view" value="<?php 
    echo esc_attr($view);
    ?>
"/>

				<?php 
    if (isset($_GET['download-id'])) {
        ?>
					<input type="hidden" name="download-id" value="<?php 
        echo absint($_GET['download-id']);
        ?>
"/>
				<?php 
    }
    ?>

				<select id="edd-graphs-date-options" name="range">
				<?php 
    foreach ($date_options as $key => $option) {
        ?>
						<option value="<?php 
        echo esc_attr($key);
        ?>
"<?php 
        selected($key, $dates['range']);
        ?>
><?php 
        echo esc_html($option);
        ?>
</option>
					<?php 
    }
    ?>
				</select>

				<div id="edd-date-range-options" <?php 
    echo $display;
    ?>
>
					<span><?php 
    _e('From', 'easy-digital-downloads');
    ?>
&nbsp;</span>
					<select id="edd-graphs-month-start" name="m_start">
						<?php 
    for ($i = 1; $i <= 12; $i++) {
        ?>
							<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['m_start']);
        ?>
><?php 
        echo edd_month_num_to_name($i);
        ?>
</option>
						<?php 
    }
    ?>
					</select>
					<select id="edd-graphs-day-start" name="day">
						<?php 
    for ($i = 1; $i <= 31; $i++) {
        ?>
							<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['day']);
        ?>
><?php 
        echo $i;
        ?>
</option>
						<?php 
    }
    ?>
					</select>
					<select id="edd-graphs-year-start" name="year">
						<?php 
    for ($i = 2007; $i <= date('Y'); $i++) {
        ?>
							<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['year']);
        ?>
><?php 
        echo $i;
        ?>
</option>
						<?php 
    }
    ?>
					</select>
					<span><?php 
    _e('To', 'easy-digital-downloads');
    ?>
&nbsp;</span>
					<select id="edd-graphs-month-end" name="m_end">
						<?php 
    for ($i = 1; $i <= 12; $i++) {
        ?>
							<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['m_end']);
        ?>
><?php 
        echo edd_month_num_to_name($i);
        ?>
</option>
						<?php 
    }
    ?>
					</select>
					<select id="edd-graphs-day-end" name="day_end">
						<?php 
    for ($i = 1; $i <= 31; $i++) {
        ?>
							<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['day_end']);
        ?>
><?php 
        echo $i;
        ?>
</option>
						<?php 
    }
    ?>
					</select>
					<select id="edd-graphs-year-end" name="year_end">
						<?php 
    for ($i = 2007; $i <= date('Y'); $i++) {
        ?>
						<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['year_end']);
        ?>
><?php 
        echo $i;
        ?>
</option>
						<?php 
    }
    ?>
					</select>
				</div>

				<div class="edd-graph-filter-options graph-option-section">
					<input type="checkbox" id="exclude_taxes" <?php 
    checked(false, $taxes, true);
    ?>
 value="1" name="exclude_taxes" />
					<label for="exclude_taxes"><?php 
    _e('Exclude Taxes', 'easy-digital-downloads');
    ?>
</label>
				</div>

				<div class="edd-graph-filter-submit graph-option-section">
					<input type="hidden" name="edd_action" value="filter_reports" />
					<input type="submit" class="button-secondary" value="<?php 
    _e('Filter', 'easy-digital-downloads');
    ?>
"/>
				</div>
			</div>
		</div>
	</form>
	<?php 
}
/**
 * Get CC Form
 *
 * @access      private
 * @since       1.0
 * @return      void
*/
function edd_get_cc_form()
{
    ob_start();
    ?>

	<?php 
    do_action('edd_before_cc_fields');
    ?>

	<fieldset id="edd_cc_fields" class="edd-do-validate">
		<legend><?php 
    _e('Credit Card Info', 'edd');
    ?>
</legend>
		<p>
			<input type="text" autocomplete="off" name="card_number" class="card-number edd-input required" placeholder="<?php 
    _e('Card number', 'edd');
    ?>
" />
			<label class="edd-label"><?php 
    _e('Card Number', 'edd');
    ?>
<span class="card-type"></span></label>
		</p>
		<p>
			<input type="text" size="4" autocomplete="off" name="card_cvc" class="card-cvc edd-input required" placeholder="<?php 
    _e('Security code', 'edd');
    ?>
" />
			<label class="edd-label"><?php 
    _e('CVC', 'edd');
    ?>
</label>
		</p>
		<p>
			<input type="text" autocomplete="off" name="card_name" class="card-name edd-input required" placeholder="<?php 
    _e('Card name', 'edd');
    ?>
" />
			<label class="edd-label"><?php 
    _e('Name on the Card', 'edd');
    ?>
</label>
		</p>
		<?php 
    do_action('edd_before_cc_expiration');
    ?>
		<p class="card-expiration">
			<select name="card_exp_month" class="card-expiry-month required">
				<?php 
    for ($i = 1; $i <= 12; $i++) {
        echo '<option value="' . $i . '">' . $i . '&nbsp;' . edd_month_num_to_name($i) . '</option>';
    }
    ?>
			</select>
			<span class="exp-divider"> / </span>
			<select name="card_exp_year" class="card-expiry-year required">
				<?php 
    for ($i = date('Y'); $i <= date('Y') + 10; $i++) {
        echo '<option value="' . $i . '">' . $i . '</option>';
    }
    ?>
			</select>
			<label class="edd-label"><?php 
    _e('Expiration (MM/YYYY)', 'edd');
    ?>
</label>
		</p>
		<?php 
    do_action('edd_after_cc_expiration');
    ?>

	</fieldset>

	<?php 
    do_action('edd_after_cc_fields');
    ?>

	<?php 
    echo ob_get_clean();
}
/**
 * Show report graph date filters
 *
 * @access      public
 * @since       1.3
 * @return      void
*/
function edd_reports_graph_controls()
{
    $date_options = apply_filters('edd_report_date_options', array('this_month' => __('This Month', 'edd'), 'last_month' => __('Last Month', 'edd'), 'this_quarter' => __('This Quarter', 'edd'), 'last_quarter' => __('Last Quarter', 'edd'), 'this_year' => __('This Year', 'edd'), 'last_year' => __('Last Year', 'edd'), 'other' => __('Other', 'edd')));
    $dates = edd_get_report_dates();
    $display = $dates['range'] == 'other' ? '' : 'style="display:none;"';
    $view = isset($_GET['view']) ? $_GET['view'] : 'earnings';
    ?>
	<form id="edd-garphs-filter" method="get">
		<div class="tablenav top">
			<div class="alignleft actions">

		       	<input type="hidden" name="post_type" value="download"/>
		       	<input type="hidden" name="page" value="edd-reports"/>
		       	<input type="hidden" name="view" value="<?php 
    echo $view;
    ?>
"/>

		       	<select id="edd-graphs-date-options" name="range">
		       		<?php 
    foreach ($date_options as $key => $option) {
        echo '<option value="' . esc_attr($key) . '" ' . selected($key, $dates['range']) . '>' . esc_html($option) . '</option>';
    }
    ?>
		       	</select>

		       	<div id="edd-date-range-options" <?php 
    echo $display;
    ?>
>
					&mdash;
				    <span><?php 
    _e('From', 'edd');
    ?>
&nbsp;</span>
			       	<select id="edd-graphs-month-start" name="m_start">
			       		<?php 
    for ($i = 1; $i <= 12; $i++) {
        ?>
			       			<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['m_start']);
        ?>
><?php 
        echo edd_month_num_to_name($i);
        ?>
</option>
				       	<?php 
    }
    ?>
			       	</select>
			       	<span><?php 
    _e('To', 'edd');
    ?>
&nbsp;</span>
			       	<select id="edd-graphs-month-start" name="m_end">
			       		<?php 
    for ($i = 1; $i <= 12; $i++) {
        ?>
			       			<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['m_end']);
        ?>
><?php 
        echo edd_month_num_to_name($i);
        ?>
</option>
				       	<?php 
    }
    ?>
			       	</select>
			       	<select id="edd-graphs-year" name="year">
			       		<?php 
    for ($i = 2007; $i <= $dates['year_end']; $i++) {
        ?>
			       			<option value="<?php 
        echo absint($i);
        ?>
" <?php 
        selected($i, $dates['year']);
        ?>
><?php 
        echo $i;
        ?>
</option>
				       	<?php 
    }
    ?>
			       	</select>
			    </div>

			    <input type="hidden" name="edd_action" value="filter_reports" />
		       	<input type="submit" class="button-secondary" value="<?php 
    _e('Filter', 'edd');
    ?>
"/>
			</div>
		</div>
	</form>
	<?php 
}
 /**
  * Renders an HTML Dropdown of months
  *
  * @access public
  * @since 1.5.2
  * @param string $name Name attribute of the dropdown
  * @param int    $selected Month to select automatically
  * @return string $output Month dropdown
  */
 public function month_dropdown($name = 'month', $selected = 0)
 {
     $month = 1;
     $output = '<select name="' . esc_attr($name) . '" id="' . esc_attr($name) . '">';
     while ($month <= 12) {
         $output .= '<option value="' . absint($month) . '"' . selected($selected, $month, false) . '>' . edd_month_num_to_name($month) . '</option>';
         $month++;
     }
     $output .= '</select>';
     return $output;
 }