public function overwriteForm($return, $returnfull)
 {
     $channel = new NewsChannel();
     $temp = $channel->getWhere("channel_active=1 AND channel_type = 'webapps'");
     foreach ($temp as $c) {
         $arrChannel[$c->channel_id] = $c->channel_name;
     }
     $return['webapps_channel_id'] = new Leap\View\InputSelect($arrChannel, "webapps_channel_id", "webapps_channel_id", $this->webapps_channel_id);
     return $return;
 }
 public function overwriteForm($return, $returnfull)
 {
     $return['news_author'] = new Leap\View\InputText("hidden", "news_author", "news_author", Account::getMyID());
     $return['news_comment_allow'] = new Leap\View\InputSelect(array('0' => "No", '1' => "Yes"), "news_comment_allow", "news_comment_allow", $this->news_comment_allow);
     $return['news_commentcount'] = new Leap\View\InputText("hidden", "news_commentcount", "news_commentcount", $this->news_commentcount);
     $return['news_validity_begin'] = new Leap\View\InputText("date", "news_validity_begin", "news_validity_begin", $this->news_validity_begin);
     $return['news_validity_end'] = new Leap\View\InputText("date", "news_validity_end", "news_validity_end", $this->news_validity_end);
     if (isset($_GET['load']) && $_GET['load']) {
         $return['news_postdate'] = new Leap\View\InputText("hidden", "news_postdate", "news_postdate", $this->news_postdate);
     } else {
         $return['news_postdate'] = new Leap\View\InputText("hidden", "news_postdate", "news_postdate", leap_mysqldate());
     }
     $return['news_updatedate'] = new Leap\View\InputText("hidden", "news_updatedate", "news_updatedate", leap_mysqldate());
     $channel = new NewsChannel();
     $temp = $channel->getWhere("channel_active=1 AND channel_type = 'content'");
     foreach ($temp as $c) {
         $arrChannel[$c->channel_id] = $c->channel_name;
     }
     $return['news_channel_id'] = new Leap\View\InputSelect($arrChannel, "news_channel_id", "news_channel_id", $this->news_channel_id);
     return $return;
 }
    public function NewsChannelMatrix()
    {
        $t = time();
        //create matrix to adjust menu
        $ro = new RoleOrganization();
        $arr = $ro->getWhere("organization_active = 1");
        $chn = new NewsChannel();
        $arrChn = $chn->getWhere("channel_active = 1");
        $curlvl = "";
        ?>
<script>
    var channelSelected = [];
</script>
<style>
    select option.no_text{
        color: #dedede !important;
    }
    .selectchannel{
       
        margin-bottom:30px;
    }
    .buttonselectchannel{
        border-radius: 5px;
        background-color: #efefef; 
        float:left;
        padding: 10px;
        margin: 5px;
        cursor:pointer;
    }
    .buttonselectchannelactive{
        background-color: #bbb;
        text-decoration:line-through;
    }
</style>
<div class="selectchannel">
    <?php 
        foreach ($arrChn as $ch) {
            ?>
    <div class="buttonselectchannel buttonselectchannelactive" id="chan_<?php 
            echo $ch->channel_id;
            ?>
_<?php 
            echo $t;
            ?>
"><?php 
            echo $ch->channel_name;
            ?>
</div>
    <script>
        $("#chan_<?php 
            echo $ch->channel_id;
            ?>
_<?php 
            echo $t;
            ?>
").click(function(){
            for(var x in channelSelected){
                //console.log(x+" in2222 "+channelSelected[x]);
                $("#chan_"+channelSelected[x]+"_<?php 
            echo $t;
            ?>
").addClass("buttonselectchannelactive");
                $('.channel_form_'+channelSelected[x]).hide();
            }
            var index = jQuery.inArray("<?php 
            echo $ch->channel_id;
            ?>
", channelSelected);
            //console.log(index);
            if(index == -1){
                channelSelected.push("<?php 
            echo $ch->channel_id;
            ?>
");
            }else{
                //var index2 = channelSelected.indexOf("<?php 
            echo $ch->channel_id;
            ?>
");
                channelSelected.splice(index,1);
                /*$("#chan_"+channelSelected[index2]+"_<?php 
            echo $t;
            ?>
").removeClass("buttonselectchannelactive");
                console.log("in");
                console.log(index2);
                for(var x in channelSelected){
                  if(channelSelected[x] =="<?php 
            echo $ch->channel_id;
            ?>
" )
                        channelSelected.splice(x,1);
                        $("#chan_"+channelSelected[x]+"_<?php 
            echo $t;
            ?>
").removeClass("buttonselectchannelactive");
                }*/
            }
            
            for(var x in channelSelected){
                //console.log(x+" in "+channelSelected[x]);
                $("#chan_"+channelSelected[x]+"_<?php 
            echo $t;
            ?>
").removeClass("buttonselectchannelactive");
                $('.channel_form_'+channelSelected[x]).show();
            }
        });
    </script>
    <?php 
        }
        ?>
</div>
<div  style="margin-bottom:20px; clear:both;"></div>
<div class="table-responsive">
    <table class="table table-bordered table-striped table-hover">
        <thead>
            <tr>
                <td><?php 
        echo Lang::t('Department');
        ?>
</td>
                <?php 
        foreach ($arrChn as $ch) {
            ?>
                <td  style="display:none;" class="channel_form_<?php 
            echo $ch->channel_id;
            ?>
"><?php 
            echo $ch->channel_name;
            ?>
</td>
                <?php 
        }
        ?>
            </tr>
        </thead>
        <tbody>
            <?php 
        $rl = new RoleLevel();
        $existingRoles = $rl->getWhere("level_active = 1 ORDER BY level_tingkatan ASC");
        $nc = new NewsChannel2Org();
        $arrNC = $nc->getAll();
        if (isset($arrNC)) {
            foreach ($arrNC as $cn) {
                $arrNN[$cn->c2d_id] = $cn;
            }
        }
        //pr($existingRoles);
        foreach ($arr as $org) {
            if ($org->organization_id == '1') {
                continue;
            }
            ?>
            <tr>
                <td><?php 
            echo $org->organization_name;
            ?>
</td>
                <?php 
            foreach ($arrChn as $ch) {
                $menu = $org->organization_id . "_" . $ch->channel_id;
                ?>
                <td class="channel_form_<?php 
                echo $ch->channel_id;
                ?>
" style="display:none;">
                    <select id="role_lvl_<?php 
                echo $menu;
                ?>
_<?php 
                echo $t;
                ?>
">
                        <option class="no_text" value="no"></option>
                <?php 
                foreach ($existingRoles as $ro) {
                    $id = $ch->channel_id . "_" . $org->organization_id;
                    $curlvl = "0";
                    if (isset($arrNN[$id])) {
                        $curlvl = $arrNN[$id]->c2d_level_id;
                    }
                    ?>
                
                        <option value="<?php 
                    echo $ro->level_id;
                    ?>
" <?php 
                    if ($ro->level_id == $curlvl) {
                        echo "selected";
                    }
                    ?>
><?php 
                    echo $ro->level_name;
                    ?>
</option>
                <?php 
                }
                ?>
                    </select>
                    <script>
                    $("#role_lvl_<?php 
                echo $menu;
                ?>
_<?php 
                echo $t;
                ?>
").change(function(){
                        
                       var slc = $("#role_lvl_<?php 
                echo $menu;
                ?>
_<?php 
                echo $t;
                ?>
").val();
                       //if(slc != "no")
                       $.get("<?php 
                echo _SPPATH;
                ?>
NewsChannelWeb/ins?org=<?php 
                echo $org->organization_id;
                ?>
&chn=<?php 
                echo $ch->channel_id;
                ?>
&level_id="+slc,function(data){
                           //alert(data);
                       }); 
                    });    
                    </script>
                </td>
                <?php 
            }
            ?>
            </tr>
            <?php 
        }
        ?>
        </tbody>
       
    </table>
</div>    
        <?php 
    }
?>
                <span class="help-block" id="warning_post_files"></span>
    </div>
</div>
  
  
  <!-- channel tambahan -->
  <div id="formgroup_page_channel_id" class="form-group">
        <label for="page_channel_id" class="col-sm-2 control-label"><?php 
echo Lang::t('page_channel_id');
?>
</label>
        <div class="col-sm-10">
            <?php 
$gal2 = new NewsChannel();
$arrGal = $gal2->getWhere("channel_active =1 AND channel_type = 'content' ORDER BY channel_name ASC");
?>
            <select class="form-control" name="page_channel_id" id="page_channel_id">
                
                <?php 
if (!isset($obj->page_channel_id) || $obj->page_channel_id < 1) {
    $obj->page_channel_id = 1;
}
foreach ($arrGal as $gal) {
    ?>
                <option <?php 
    if ($gal->channel_id == $obj->page_channel_id) {
        echo "selected";
    }
    ?>
 value="<?php 
 public function loadSubscription()
 {
     //get all channels
     $channel = new NewsChannel();
     $arrChannel = $channel->getWhere("channel_active = 1");
     //get my level and org
     $org = RoleOrganization::getMy();
     $lvl = RoleLevel::getMy();
     foreach ($arrChannel as $chn) {
         $id = $chn->channel_id . "_" . $org->organization_id;
         $n = new NewsChannel2Org();
         $n->getByID($id);
         if (isset($n->c2d_level_id) && $lvl->level_id >= $n->c2d_level_id && $n->c2d_level_id) {
             $_SESSION['newsfeed'][] = $chn->channel_id;
         }
     }
 }
    public static function portalIndex()
    {
        $ch = new NewsChannel();
        $ch->getDefaultChannel();
        $cat = isset($_GET['cat']) ? addslashes($_GET['cat']) : $ch->channel_id;
        //get channel
        $arrCh = $ch->getWhere("channel_active = 1 AND channel_type = 'content'");
        $limit = 30;
        $np = new NewsPortal();
        $np->default_read_coloms = "news_page_id,news_image,news_id,news_title,news_validity_begin,news_channel_id,news_author";
        $arrEv = $np->getByChannelAndIsValid($cat, " AND news_status = 'publish' ORDER BY news_validity_begin DESC");
        //$jumlah = $np->getJumlahByChannelAndIsValid($cat," AND news_status = 'publish'");
        //pr($arrE);
        //pr($arrE);
        ?>
		<style>
			.news-item {
				height           : 60px;
				background-color : #e8e9d7;
				width            : 100%;
				font-family      : verdana;
				font-size        : 13px;
			}

			.white {
				background-color : #efefef;
			}

			.news-item .nfoto {
				float       : left;
				margin     : 5px;
				width       : 50px;
				height      : 50px;
				overflow    : hidden;
				margin-left : 5px;
			}

			.news-item .nfoto img {

			}

			.news-item .nmessage {
				margin-left : 65px;
				padding-top : 5px;
			}
                        .news-item .nmessage a{
				color:#555;
                                
			}
			.news-containter {
				height     : 332px;
				overflow-y : auto;
			}

			#newsfeed .viewmore {
				background-color : #e8e9d7;
				width            : 100%;
				height           : 40px;
				line-height      : 40px;
				text-align       : center;
				font-weight      : bold;
				letter-spacing   : 2px;
				cursor           : pointer;

			}

			.ago {
				font-style : italic;
				font-size  : 11px;
                                color:#888;
			}

			#newsfeed_category_selector {
				background-color : #dedede;
				padding          : 10px;
			}

			.newsfeed_selectbox {
				float : right;
				color : #555;
			}

			.newsfeed_selectbox select {
			<?php 
        $bgcolor = ThemeReg::mod("portlet_headbgcolor", "#038563", "color");
        $bgimage = ThemeReg::mod("portlet_headbg", _SPPATH . _THEMEPATH . "/images/h3bg2.jpg", "image");
        $strbgimage = '';
        if ($bgimage != "") {
            $strbgimage = 'background-image: url("' . $bgimage . '");';
        }
        $textcolor = ThemeReg::mod("portlet_headtextcolor", "#fff", "color");
        ?>
 background     : <?php 
        echo $bgcolor;
        ?>
;
			<?php 
        echo $strbgimage;
        ?>
 // background : #038563;
				color         : <?php 
        echo $textcolor;
        ?>
;
				border        : 0px;
				text-align    : right;
				padding-right : 10px;
			}

			.newsfeed_selectbox select option {
				text-align : right;
			}
		</style>

		<div class="col-md-8 col-md-offset-2">
			<h1 class="tbsh1"
			    style="margin-bottom:20px;">

				<i class="glyphicon glyphicon-th-large"
				   style="top:5px;"></i>
				<?php 
        echo Lang::t('News');
        ?>
				<div style="float:right;">
					<select class="form-control"
					        id="selectnewsfeed"
					        dir="rtl"
					        onchange="document.location='<?php 
        echo _SPPATH;
        ?>
newsfeed?cat='+$('#selectnewsfeed').val();">
						<?php 
        foreach ($arrCh as $ct => $chna) {
            if (NewsChannel::isSubscribe($chna->channel_id)) {
                ?>
								<option value="<?php 
                echo $chna->channel_id;
                ?>
" <?php 
                if ($cat == $chna->channel_id) {
                    echo "selected";
                }
                ?>
><?php 
                echo $chna->channel_name;
                ?>
</option>
							<?php 
            }
        }
        ?>
					</select>

				</div>

			</h1>

			<?php 
        $gw = new GalleryWeb();
        $activemon = "";
        foreach ($arrEv as $num => $ev) {
            $vname = stripslashes($ev->news_title);
            if (strlen($vname) > 60) {
                $vname = substr($vname, 0, 60) . "...";
            }
            ?>
				<div class="news-item <?php 
            if ($num % 2 == 1) {
                echo 'white';
            }
            ?>
">
					<div class="nfoto">
						<img onload="OnImageLoad(event,50);"
						     src="<?php 
            $url = _SPPATH . $gw->uploadURL . "thumbnail/" . $ev->news_image;
            if (NewsFeedWeb::isExists($url)) {
                echo $url;
            } else {
                echo _SPPATH . $gw->uploadURL . $ev->news_image;
            }
            ?>
">
					</div>
					<div class="nmessage">
						<a href="<?php 
            echo _SPPATH;
            ?>
page?id=<?php 
            echo $ev->news_page_id;
            ?>
"><?php 
            echo $vname;
            ?>
</a>

						<div class="ago">
							<?php 
            echo ago(strtotime($ev->news_validity_begin));
            ?>
						</div>
					</div>
				</div>
			<?php 
        }
        ?>
		</div>
	<?php 
    }