OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
OCP\JSON::checkAppEnabled('collaboration');
$l = OC_L10N::get('collaboration');
if (isset($_POST['member']) && isset($_POST['start']) && isset($_POST['count']) && isset($_POST['project'])) {
    if (strcasecmp($_POST['member'], OC_User::getUser()) != 0) {
        \OCP\Util::writeLog('collaboration', OC_User::getUser() . ' is trying to access posts of ' . $_POST['member'], \OCP\Util::WARN);
        OC_JSON::error();
        exit;
    }
    if ($_POST['project'] != '' && !OC_Collaboration_Project::isMemberWorkingOnProjectByTitle(OC_User::getUser(), $_POST['project'])) {
        \OCP\Util::writeLog('collaboration', OC_User::getUser() . ' is trying to access project ' . $_POST['project'], \OCP\Util::WARN);
        OC_JSON::error();
        exit;
    }
    $posts = OC_Collaboration_Post::readPosts($_POST['member'], $_POST['project'], $_POST['start'], $_POST['count']);
    $text = '';
    foreach ($posts as $each) {
        if (!isset($each['title']) || $each['title'] == '') {
            break;
        }
        $datetime = explode(' ', $each['time']);
        $text .= '<div class="unit">
		<div class="post_title">' . $each['title'] . '</div>
		
		<div class="contents">' . $each['content'] . '<br />
			<br />
			<div class="comment" >
				<button class="btn_comment" id="btn_comment_' . $each['post_id'] . '" >' . ($l->t('Comments') . ' (' . OC_Collaboration_Comment::getCommentCount($each['post_id']) . ')') . '</button>
			</div>
		</div>
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
\OCP\User::checkLoggedIn();
\OCP\App::checkAppEnabled('collaboration');
OCP\App::setActiveNavigationEntry('collaboration');
OCP\Util::addScript('collaboration', 'dashboard');
OCP\Util::addStyle('collaboration', 'tabs');
OCP\Util::addStyle('collaboration', 'content_header');
OCP\Util::addStyle('collaboration', 'dashboard');
$tpl = new OCP\Template("collaboration", "dashboard", "user");
if (isset($_GET['project']) && $_GET['project'] != 'ALL') {
    if (!OC_Collaboration_Project::isMemberWorkingOnProjectByTitle(OC_User::getUser(), $_GET['project'])) {
        header('Location: ' . \OCP\Util::linkToRoute('collaboration_route', array('rel_path' => 'dashboard')));
        \OCP\Util::writeLog('collaboration', OC_User::getUser() . ' is trying to access project ' . $_GET['project'], \OCP\Util::WARN);
        exit;
    } else {
        $tpl->assign('project', $_GET['project']);
        $tpl->assign('posts', OC_Collaboration_Post::readPosts(OC_User::getUser(), $_GET['project']));
        $task_params["assigned_by"] = OC_User::getUser();
        $task_params["project"] = $_GET['project'];
        $tpl->assign('tasks', OC_Collaboration_Task::readTasks($task_params));
    }
} else {
    $tpl->assign('posts', OC_Collaboration_Post::readPosts(OC_User::getUser()));
    $task_params["assigned_to"] = OC_User::getUser();
    $tpl->assign('tasks', OC_Collaboration_Task::readTasks($task_params));
}
$tpl->printPage();