<?php
/**
 * @version        1.9.7
 * @package        Joomla
 * @subpackage     EDocman
 * @author         Tuan Pham Ngoc
 * @copyright      Copyright (C) 2011 - 2025 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */

// No direct access
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\Utilities\ArrayHelper;

class EDocmanController extends OSControllerAdmin
{

	/**
	 * Method to display a view.
	 *
	 * @param    boolean $cachable  If true, the view output will be cached
	 * @param    array   $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
	 *
	 * @return    OSControllerAdmin        This object to support chaining.
	 */
	public function display($cachable = false, array $urlparams = array())
	{
		$document = Factory::getApplication()->getDocument();
		EdocmanHelper::addStyleSheet(Uri::root() . 'components/com_edocman/assets/css/style.css');
		EdocmanHelper::addStyleSheet('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css');
		if(EdocmanHelper::isJoomla4())
		{
			EdocmanHelper::addStyleSheet(Uri::root() . 'components/com_edocman/assets/css/style4.css');
		}
        EdocmanHelper::addStyleSheet(Uri::root() . 'components/com_edocman/assets/css/font.css');
		$customCss = JPATH_ROOT . '/components/com_edocman/assets/css/custom.css';
		if (file_exists($customCss) && filesize($customCss))
		{
			EdocmanHelper::addStyleSheet(Uri::root() . 'components/com_edocman/assets/css/custom.css');
		}

		$db		= Factory::getContainer()->get('db');
		$db->setQuery("Update #__edocman_configs set config_value = '5' where config_key = 'twitter_bootstrap_version' and config_value in ('','2','3')");
		$db->execute();

		$config = EDocmanHelper::getConfig();

		
		if ($config->load_bootstrap_css !== '0')
		{
			HTMLHelper::_('bootstrap.loadCss');
		}
		

		//Load jquery here
		if ($config->load_jquery !== '0')
		{
			EDocmanHelper::loadJQuery();
		}
		parent::display($cachable, $urlparams);

		return $this;
	}
	
	public function category_save_order_ajax()
	{
		// Get the input
		$pks = $this->input->post->get('cid', array(), 'array');
		$order = $this->input->post->get('order', array(), 'array');

		// Sanitize the input
        $pks    = ArrayHelper::toInteger($pks);
        $order  = ArrayHelper::toInteger($order);

		// Get the model
		$model = $this->getModel('Managecategories');
		// Save the ordering
		$return = $model->saveCategoryOrder($pks, $order);

		if ($return)
		{
			echo "1";
		}

		// Close the application
		$this->app->close();
	}


	/***
	 * Get search parameters from search module and performing redirect
	 */
	public function search()
	{
		$categoryId		= $this->input->getInt('filter_category_id', 0);
		$search			= $this->input->getString('filter_search', '');
		$layout			= $this->input->getCmd('layout', '');
		$Itemid			= $this->input->getInt('Itemid', 0);
		$show_category	= $this->input->getInt('show_category',0);
		$fileType		= $this->input->get('fileType',array(),'array');
		$show_searchform= $this->input->getInt('show_searchform',0);
		$searchphrase	= $this->input->getString('searchphrase','all');

		$url = 'index.php?option=com_edocman&view=search';
		if ($categoryId)
		{
			$url .= '&filter_category_id=' . $categoryId;
		}


		if ($search)
		{
			$url .= '&filter_search=' . urlencode($search);
		}

		if ($layout)
		{
			$url .= '&layout=' . $layout;
		}

		$url .= '&show_category='. $show_category.'&searchphrase='.$searchphrase;

		if(count($fileType) > 0){
			$url .= '&filter_filetype='.implode("-",$fileType);
		}
		$url .= '&show_searchform='.$show_searchform;
		$url .= '&Itemid=' . $Itemid;

		$this->app->redirect(Route::_($url, false, 0));
	}

	public function editcategory()
    {
        //$categoryId     = $this->input->getInt('id',0);
        $categoryId     = 0;
		$return			= $this->input->getString('return','');
        $cid            = $this->input->get('cid',array(),'array');
        if(count($cid))
        {
            $categoryId = $cid[0];
        }
        $Itemid			= $this->input->getInt('Itemid', 0);
		$manage			= $this->input->getInt('manage', 0);
        $url = 'index.php?option=com_edocman&view=editcategory&return='.$return;
        if ($categoryId)
        {
            $url .= '&id=' . $categoryId;
        }
        $url .= '&Itemid=' . $Itemid;
		$url .= '&manage=' . $manage;
        $this->app->redirect(Route::_($url, false, 0));
    }

    public function login()
    {
        $jinput						= $this->app->input;
        $mainframe					= Factory::getApplication('site');
        if ($return = $jinput->get('return', '' , 'base64'))
        {
            $return = base64_decode($return);
            if (!JURI::isInternal($return))
            {
                $return = '';
            }
        }
        $options					= [];
        $options['return']			= $return;
        $credentials				= [];
        $credentials['username']	= $jinput->getString('username','');
        $credentials['password']	= $jinput->get('password','','RAW');
        //preform the login action
        $error						= $mainframe->login($credentials, $options);
        if(!$error)
        {
            echo Text::_('EDOCMAN_LOGIN_FAIL');
        }
        $this->app->close();
    }

    public function unsubscribe()
    {
	    $jinput = $this->app->input;
	    $email = $jinput->getString('email','');
	    if($email != '')
	    {
            $db = Factory::getContainer()->get('db');
            $query = $db->getQuery(true);
            $query->select('count(id)')->from('#__edocman_unsubscribe_emails')->where('email like "'.$email.'"');
            $db->setQuery($query);
            $count = $db->loadResult();
            if($count > 0)
            {
                Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_YOU_ALREADY_UNSUBSCRIBE_OF_MAILING_LIST'));
            }
            else
            {
                $query->clear();
                $query->clear();
                $values = array('NULL', $db->quote($email));
                $query->insert($db->quoteName('#__edocman_unsubscribe_emails'))->columns(array('id','email'))->values(implode(',',$values));
                $db->setQuery($query);
                $db->execute();
                Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_YOUR_EMAIL_HAS_JUST_BEEN_UNSUBSCRIBED'));
            }
        }
        return;
    }

    public function savecategory()
    {
		$db			= Factory::getContainer()->get('db');
        $user		= Factory::getApplication()->getIdentity();
        $model		= $this->getModel('Editcategory');
		$addsubcat	= Factory::getApplication()->getInput()->getInt('addsubcat',0);
		$manage		= Factory::getApplication()->getInput()->getInt('manage',0);
        $category	= $model->saveCategory($this->input);
		$Itemid	    = Factory::getApplication()->getInput()->getInt('Itemid', 0);
        Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_CATEGORY_HAS_BEEN_SAVED'));
		$return = $this->app->input->getString('return','');
		if($return != "")
		{
			$return = base64_decode($return);
			$this->app->redirect($return);
		}
        elseif ($user->authorise('core.manage_categories', 'com_edocman') && $manage == 1)
        {
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories'));
        }
        else
        {
			if($addsubcat == 1)
			{
				if($category > 0)
				{
					$query = $db->getQuery(true);
					$query->select('parent_id')->from('#__edocman_categories')->where('id='.$category);
					$db->setQuery($query);
					$parent_id = $db->loadResult();
				}
				if((int)$parent_id > 0)
				{
					$category = $parent_id;
				}
				
				Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=category&id='.$category.'&Itemid='.$Itemid));
			}
			else
			{
				if($category > 0)
				{
					$query = $db->getQuery(true);
					$query->select('parent_id')->from('#__edocman_categories')->where('id='.$category);
					$db->setQuery($query);
					$parent_id = $db->loadResult();
				}
				if((int)$parent_id > 0)
				{
					$category = $parent_id;
				}
				Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=category&id='.$category));
			}
        }
    }

    public function deletecategory()
    {
        $user = Factory::getApplication()->getIdentity();
		$manage		= Factory::getApplication()->getInput()->getInt('manage',0);
        $parentId   = Factory::getApplication()->getInput()->getInt('parentId',0);
        $canDelete = $user->authorise('edocman.manage_categories', 'com_edocman');
        if(! $canDelete && $parentId > 0)
        {
            $canDelete = $user->authorise('edocman.manage_subcategories', 'com_edocman.category.'.$parentId);
        }
        if ($canDelete)
        {
            $cid = Factory::getApplication()->getInput()->get('cid', array(), 'array');
            $model = $this->getModel('Editcategory');
            $model->deleteCategory($cid);
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_CATEGORIES_HAVE_BEEN_DELETED'));
            if ($user->authorise('core.manage_categories', 'com_edocman') && $manage == 1)
            {
                Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories'));
            }
            else
            {
				$return = $this->app->input->getString('return','');
				if($return != "")
				{
					$return = base64_decode($return);
					Factory::getApplication()->redirect($return);
				}
                Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=category&id='.$parentId));
            }
        }
        else
        {
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_NOT_ALLOWED_ACTION'));
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories'));
        }
    }

    public function canceleditcategory()
    {
		$return = $this->app->input->getString('return','');
		if($return != "")
		{
			$return = base64_decode($return);
			$this->app->redirect($return);
		}
        Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories'));
    }

    public function publishcategory()
    {
		$itemId = Factory::getApplication()->getInput()->getInt('Itemid', 0);
        if(Factory::getApplication()->getIdentity()->authorise('core.delete','com_edocman'))
        {
            $cid   = Factory::getApplication()->getInput()->get('cid',array(),'array');
            $model = $this->getModel('Editcategory');
            $model->changeCategoryState($cid,1);
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_CATEGORIES_HAVE_BEEN_PUBLISHED'));
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories&Itemid='.$itemId));
        }
        else
        {
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_NOT_ALLOWED_ACTION'));
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories&Itemid='.$itemId));
        }
    }

    public function unpublishcategory()
    {
		$itemId = Factory::getApplication()->getInput()->getInt('Itemid', 0);
        if(Factory::getApplication()->getIdentity()->authorise('core.delete','com_edocman'))
        {
            $cid   = Factory::getApplication()->getInput()->get('cid',array(),'array');
            $model = $this->getModel('Editcategory');
            $model->changeCategoryState($cid,0);
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_CATEGORIES_HAVE_BEEN_PUBLISHED'));
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories&Itemid='.$itemId));
        }
        else
        {
            Factory::getApplication()->enqueueMessage(Text::_('EDOCMAN_NOT_ALLOWED_ACTION'));
            Factory::getApplication()->redirect(Route::_('index.php?option=com_edocman&view=managecategories&Itemid='.$itemId));
        }
    }

	public function tags()
	{
		$app		= Factory::getApplication();
		$input		= $app->getInput();
        $db			= Factory::getContainer()->get('db');
        $word		= $input->getString('q', null);
        $id			= $input->getInt('id');
        $word		= $db->Quote($db->escape($word, true).'%', false);

        if ($id) {
            $query = "SELECT id,tag FROM #__edocman_tags WHERE tag LIKE ".$word;
            $db->setQuery($query);
            $result = $db->loadObjectList();
        } else {
            $query = "SELECT tag FROM #__edocman_tags WHERE tag LIKE ".$word;
            $db->setQuery($query);
            $result = $db->loadColumn();
        }

        echo json_encode($result);
        $app->close();
	}

	public function loadCalendar()
	{
		$app		= Factory::getApplication();
		$lang = Factory::getLanguage();
		$tag = $lang->getTag();
		if (!$tag)
			$tag = 'en-GB';

		$lang->load('mod_edocmancalendar', JPATH_ROOT.'/modules/mod_edocmancalendar', $tag);
		$input		= $app->getInput();
		$db			= Factory::getContainer()->get('db');
		
		$mid		= $input->getInt('mid');
		$curmonth   = $input->getInt('defmonth',date('n'));
		$curyear	= $input->getInt('defyear',date('Y'));
		$curmonth	= $input->getInt('month', $curmonth);
		$curyear	= $input->getInt('year', $curyear);
		$firstday   = $input->getString('firstday','');
		$submonthname = $input->getInt('submonthname',0);
		$categoryIds  = $input->getString('categoryIds','');
		$type		= $input->getInt('module_type',1);
		$linkType   = $input->getInt('link_type',0);
		$show_child_category_articles = $input->getInt('show_child_category_articles',0);
		$count		= $input->getInt('count', 10);
		$ordering	= $input->getString('ordering','c_dsc');
		$usedate	= $input->getString('usedate','created');

		$cal = new CMSObject();
	
		
		$dayofmonths=array(31,(!($curyear%400)?29:(!($curyear%100)?28:(!($curyear%4)?29:28)) ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		
		$dayofmonth = $dayofmonths[$curmonth-1];
		$day_count = 1;
		$num = 0;

		$weeks = [];
		for($i = 0; $i < 7; $i++) {
			$a=floor((14-$curmonth)/12);
			$y=$curyear-$a;
			$m=$curmonth+12*$a-2;
			$dayofweek=($day_count+$y+floor($y/4)-floor($y/100)+floor($y/400)+floor((31*$m)/12)) % 7;
			$dayofweek = $dayofweek - 1 - $firstday;
			if($dayofweek <= -1) $dayofweek =$dayofweek + 7;


			if($dayofweek == $i)
			{
				$weeks[$num][$i] = $day_count.' 0';
				$day_count++;
			}
			else
			{
				$weeks[$num][$i] = ($dayofmonths[$curmonth!=1?($curmonth-2):(11)]-($dayofweek-1-$i)).' 1';
			}
		}

		while(true) {
			$num++;
			for($i = 0; $i < 7; $i++)
			{
				if ($day_count > $dayofmonth) {
					$weeks[$num][$i] = ($day_count-$dayofmonths[$curmonth-1]).' 1';
				} elseif ($day_count <= $dayofmonth) {
					$weeks[$num][$i] = $day_count.' 0';
				}
				$day_count++;
	  
				if($day_count > $dayofmonth && $i==6) break;
			}
			if($day_count > $dayofmonth && $i==6) break;
		}
		
		$ajaxed = 1;
		
		$monthname = Text::_('EDOCMAN_MONTHNAME_' . $submonthname . '_' . $curmonth);
		//$monthname = modEdocmanCalendarHelper::encode($monthname,$params->get('encode'),$ajaxed);
		
		$cal->items = self::getList($curmonth, $curyear, $categoryIds, $type, $linkType, $show_child_category_articles, $count, $ordering, $usedate);

		$cal->weeks			= $weeks;
		$cal->curmonth		= $curmonth;
		$cal->curyear		= $curyear;
		$cal->monthname		= $monthname;
		$cal->dayofmonths	= $dayofmonths;
		$cal->ajaxed		= $ajaxed;
		
		//return $cal;

		$doc = Factory::getApplication()->getDocument();
		
		$stylesheet = 'blue-arrows.css';
		
		EdocmanHelper::addStyleSheet(Uri::root().'modules/mod_edocmancalendar/css/' . $stylesheet);
		$script = "var sfolder = '" . JURI::base(true) . "';";
		$doc->getWebAssetManager()->addInlineScript($script);
		EdocmanHelper::addScript(Uri::root().'modules/mod_edocmancalendar/assets/newscalendar.js');
		
		?>
		<?php if ($cal->ajaxed == 0) : ?>
		<div class="newscalendar" id="newscalendar<?php echo $mid; ?>"><?php endif; ?>
			<table class="nc-header" cellspacing="0">
				<thead>
					<tr>
						<td width="20"><a href="javascript:void(0)" onClick="updateNewsCalendar(<?php echo $cal->curmonth; ?>,<?php echo $cal->curyear-1; ?>,<?php echo $mid; ?>,'<?php echo $curmonth; ?>','<?php echo $curyear; ?>','<?php echo $firstday; ?>','<?php echo $submonthname; ?>', '<?php echo $categoryIds; ?>' , '<?php echo $type; ?>', '<?php echo $linkType; ?>' ,'<?php echo $show_child_category_articles; ?>','<?php echo $count; ?>', '<?php echo $ordering; ?>', '<?php echo $usedate; ?>')" class="back-yr"></a></td>

						<td width="20"><a href="javascript:void(0)" onClick="updateNewsCalendar(<?php echo ($cal->curmonth!=1?$cal->curmonth-1:12); ?>,<?php echo ($cal->curmonth!=1?$cal->curyear:$cal->curyear-1); ?>,<?php echo $mid; ?>,'<?php echo $curmonth; ?>','<?php echo $curyear; ?>','<?php echo $firstday; ?>','<?php echo $submonthname; ?>', '<?php echo $categoryIds; ?>' , '<?php echo $type; ?>', '<?php echo $linkType; ?>' ,'<?php echo $show_child_category_articles; ?>','<?php echo $count; ?>', '<?php echo $ordering; ?>', '<?php echo $usedate; ?>')" class="back-mth"></a></td>
						<td align="center"><div id="monthyear_<?php echo $mid; ?>"><span class="monthname"><?php echo $cal->monthname; ?></span> <span class="yearname"><?php echo substr($cal->curyear,2); ?></span></div></td>
						<td width="20" align="right"><a href="javascript:void(0)" onClick="updateNewsCalendar(<?php echo ($cal->curmonth!=12?$cal->curmonth+1:1); ?>,<?php echo ($cal->curmonth!=12?$cal->curyear:$cal->curyear+1); ?>,<?php echo $mid; ?>,'<?php echo $curmonth; ?>','<?php echo $curyear; ?>','<?php echo $firstday; ?>','<?php echo $submonthname; ?>', '<?php echo $categoryIds; ?>' , '<?php echo $type; ?>', '<?php echo $linkType; ?>' ,'<?php echo $show_child_category_articles; ?>','<?php echo $count; ?>', '<?php echo $ordering; ?>', '<?php echo $usedate; ?>')" class="fwd-mth"></a></td>
						<td width="20" align="right"><a href="javascript:void(0)" onClick="updateNewsCalendar(<?php echo $cal->curmonth; ?>,<?php echo $cal->curyear+1; ?>,<?php echo $mid; ?>,'<?php echo $curmonth; ?>','<?php echo $curyear; ?>','<?php echo $firstday; ?>','<?php echo $submonthname; ?>', '<?php echo $categoryIds; ?>' , '<?php echo $type; ?>', '<?php echo $linkType; ?>' ,'<?php echo $show_child_category_articles; ?>','<?php echo $count; ?>', '<?php echo $ordering; ?>', '<?php echo $usedate; ?>')" class="fwd-yr"></a></td>
					</tr>
				</thead>
			</table>
			<table class="nc-body" cellspacing="0">
				<thead>
					<tr> 
					<?php 
					for($i = $firstday; $i <= $firstday+6; $i++) : 
				  ?>    <td class="dayname dayweek<?php echo (($i>6)?($i-6):($i+1)); ?>" align="center"><?php echo Jtext::_('EDOCMAN_DAYNAME_2_' . (($i>6)?($i-6):($i+1))); ?></td>		
					<?php endfor; ?></tr>
				</thead>
				<tbody>
				<?php 
					$fday=$firstday;
					for($i = 0; $i < count($cal->weeks); $i++)
					{ 
					?><tr class="week<?php echo $i+1; ?>">
						<?php
						for($j=0; $j < 7; $j++)	
						{
							if(!empty($cal->weeks[$i][$j])) 
							{
								$day = explode(' ',$cal->weeks[$i][$j]);
								$class = 'nc-day';	
								$ul = '';				
								if ( $day[1] ) { 
									$class .= " outofmonth";
								} else {
									$class .= " weekday".((($j+$fday)>6)?(($j+$fday)-6):($j+$fday+1)) . " relday" . ($j+1);	
									if ($day[0]==date('j') && $cal->curmonth==date('m')) {
										$class .= " today";	
									}
								}
								if (isset($cal->items[$day[0]]) && !$day[1]) {
									$class .= " hasitems";	
								}
								?><td><span class="<?php echo $class; ?>"><?php 
									echo $day[0];
									if (isset($cal->items[$day[0]]) && !$day[1]) { ?>
									
									<ul class="nc-items"><?php
									
									foreach ($cal->items[$day[0]] as $item) { ?> 
										<li><a href="<?php echo preg_replace('/modules\/mod_edocmancalendar\/assets\//', '', $item->link); ?>"><?php echo $item->title; ?></a></li><?php }
									?></ul>
								<?php } 
							   ?></span></td>
							<?php } else { ?>
							<td></td><?php
							}
						} ?>
						</tr>
				<?php } ?>
					
				</tbody>
			</table>
			<?php if ($cal->ajaxed == 0) : ?>
			<div class="bgimgcall"><img src="<?php echo Uri::root(); ?>modules/mod_edocmancalendar/assets/opacity.png" /></div>
		</div><?php endif; 

	}


	public static function getList($curmonth, $curyear, $categoryIds, $type, $linkType, $includeChildrenCategories, $count, $ordering, $usedate)
	{
		$db = Factory::getContainer()->get('db');
		$jinput						= Factory::getApplication()->getInput();
		$user = Factory::getApplication()->getIdentity();
		
		JLoader::register('EDocmanModelCategory', JPATH_ROOT . '/components/com_edocman/model/category.php');
		$model = OSModel::getInstance('Category', 'EDocmanModel')
			->reset()
			->limitstart(0)
			->limit($count);
		switch($ordering){
			case "c_dsc":
				$model->set('filter_order','tbl.created_time');
				$model->set('filter_order_Dir','desc');
			break;
			case "m_dsc":
				$model->set('filter_order','tbl.modified_time');
				$model->set('filter_order_Dir','desc');
			break;
			case "p_dsc":
				$model->set('filter_order','tbl.publish_up');
				$model->set('filter_order_Dir','desc');
			break;
		}
		$model->set('filter_category_ids',$categoryIds);
		if ($includeChildrenCategories)
		{
			$model->setIncludeChildren(true);
		}

		$startDateRange = $curyear . '-' . $curmonth . '-01 00:00:00';
		$endDateRange   = $curyear . '-' . ($curmonth + 1) . '-01 00:00:00';
		if ( $curmonth == 12 ) {
			$endDateRange = ($curyear + 1) . '-01-01 00:00:00';
		}
		$model->set('filter_startdate',$startDateRange);
		$model->set('filter_enddate',$endDateRange);
		$model->set('filter_datetype',$usedate);

		$items        = $model->getData();
		foreach ($items as &$item) {
			$category	= EdocmanHelper::getDocumentCategory($item->id);
			$catId		= $category->id;
			$Itemid		= EDocmanHelperRoute::getDocumentMenuId($item->id,$catId,$jinput->getInt('Itemid',0));
			$item->link = Route::_('index.php?option=com_edocman&view=document&id='.$item->id.'&catid='.$catId.'&Itemid='.$Itemid);
			switch ($usedate) {
				case 'publish':
					$item->day = HTMLHelper::_('date',strtotime($item->publish_up), 'j');
					$calitems[$item->day][] = $item;
				break;
				case 'modified':
					$item->day = HTMLHelper::_('date',strtotime($item->modified), 'j');
					$calitems[$item->day][] = $item;
				break;
				default:
					$item->day = HTMLHelper::_('date',strtotime($item->created_time), 'j');
					$calitems[$item->day][] = $item;
				break;
			}
		}
		return $calitems;
	}
}
