<?
//    require_once("../../server/table.class.php");
//    require_once("h.module.php");
//    error_reporting(E_ALL);
    //////////////////// News /////////////////////////
    function get_news(){
        $table = new Table("news");
        $resultArray = $table->findWhere("active=1");

        foreach($resultArray as $newsItem){
            echo'<div '.$table->getLiveEditAttr($newsItem['id']). '>';
            echo$newsItem['name'];
            echo"<a href='news2.php?id=".$newsItem['id']."'><img src='".$newsItem['picture']."'/></a>";
            echo$newsItem['date'];
            echo$newsItem['text'];
            echo'</div>';
        }
    }


    function get_news_single(){
        $id=trime($_GET['id']);
        $table = new Table("news");
        $resultArray = $table->findWhere("active=1 and id=$id");

        foreach($resultArray as $newsItem){
            //echo'<div '.$table->getLiveEditAttr($newsItem['id']). '>';
            echo$newsItem['name'];
            echo"<img src='".$newsItem['picture']."'/>";
            echo$newsItem['date'];
            echo$newsItem['text'];
            //echo'</div>';
        }
    }






    //////////////////// Main Module /////////////////////////
    function get_home_text(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
            echo $mainItem['home_text'];
            echo'</div>';
        }
    }

    function get_copyright(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
            echo $mainItem['copyright_notice'];
            echo'</div>';
        }
    }

    function get_contact_text(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
            echo $mainItem['contact_page_text'];
            echo'</div>';
        }
    }

    function get_careers_text(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
            echo $mainItem['careers_page_text'];
            echo'</div>';
        }
    }

    function get_map(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            if ($mainItem['google_map_iframe'] != ""){
                echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
                echo $mainItem['google_map_iframe'];
                echo'</div>';
            }
        }
    }

    function get_pdf(){
        $table = new Table("main");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $mainItem){
            if ($mainItem['corporate_pdf_catalogue'] != ""){
                echo'<div '.$table->getLiveEditAttr($mainItem['id']). '>';
                echo "<a target='_blank' href='".$mainItem['corporate_pdf_catalogue']."'>DOWNLOAD ".$mainItem['corporate_pdf_catalogue']."</a>";
                echo'</div>';
            }
        }
    }



    //////////////////// SOCIAL /////////////////////////
    #fb
    function get_fb(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['facebook'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['facebook']."'><img src='images/socialicons/facebook.png'/></a>";
            }
        }
    }
    #twitter
    function get_twitter(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['twitter'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['twitter']."'><img src='images/socialicons/twitter.png'/></a>";
            }
        }
    }
    #youtube
    function get_youtube(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['youtube'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['youtube']."'><img src='images/socialicons/youtube.png'/></a>";
            }
        }
    }
    #linkedin
    function get_linkedin(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['linkedin'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['linkedin']."'><img src='images/socialicons/linkedin.png'/></a>";
            }
        }
    }
    #friendster
    function get_friendster(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['friendster'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['friendster']."'><img src='images/socialicons/friendster.png'/></a>";
            }
        }
    }
    #myspace
    function get_myspace(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['myspace'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['myspace']."'><img src='images/socialicons/myspace.png'/></a>";
            }
        }
    }
    #flickr
    function get_flickr(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['flickr'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['flickr']."'><img src='images/socialicons/flickr.png'/></a>";
            }
        }
    }
    #googleplus
    function get_googleplus(){
        $table = new Table("social");
        $resultArray = $table->findWhere("id=1");
        foreach($resultArray as $socialItem){
            if ($socialItem['googleplus'] != ""){
                echo "<a class='social' target='_blank' href='".$socialItem['googleplus']."'><img src='images/socialicons/googleplus.png'/></a>";
            }
        }
    }

    //////////////////// Gallery /////////////////////////


    function get_gallery_thumbs(){
        $table = new Table("gallery");
        $resultArray = $table->findWhere("active=1 ORDER BY pos");

        foreach($resultArray as $galleryItem){
            echo'<div '.$table->getLiveEditAttr($galleryItem['id']). '>';
            echo$galleryItem['name'];
            echo"<a href='pictures.php?id=".$galleryItem['id']."'><img src='".$galleryItem['main_image']."'/></a>";
            echo$galleryItem['description'];
            echo'</div>';
        }
    }

    function get_gallery_names(){
        $table = new Table("gallery");
        $resultArray = $table->findWhere("active=1 ORDER BY pos");

        foreach($resultArray as $galleryItem){
            echo"<a href='pictures.php?id=".$galleryItem['id']."'>".$galleryItem['name'];
        }
    }


    function get_gallery_images_oo(){

        $galleryId = (int)$_GET['id']; // Get the id of the current gallery
        $currentPage = isset($_GET['p']) ? $_GET['p'] : 1 ; //Get the number of the current page the user is on
        $perPage = 2; //specify the maximum number of images to show per page
        $table = new Table('cmsgen_gallerypictures'); //select the table where images are found
        $total = $table->countWhere(" WHERE gallery_id='{$galleryId}'"); //count the total number of images found for that specfic gallery
        $pagination = new Pagination($currentPage,$perPage,$total); // this code right here makes pagination super easy

        $result_array = $table->findPaginate($pagination); //find paginate is a find function that automatically paginates when a $pagination object is passed

        //here is the code that you wrote...
        echo "<div style='float:right;'>";

        $gallery_name=getfield($galleryId,"name","cmsgen_galleries");
        echo "<h3 style='text-indent:40px;'>".$gallery_name."</h3>";
        echo "<table width='578'><tr><td width='39'>";
        echo "</td><td width='500'>";
        echo "<ul style='width:510px; height:500px;'>";

        //loop through the result array of the images
        foreach($result_array as $image){
            echo "<li style='float:left; margin-right:2px; margin-left:2px;'>";
            echo '<img src="'.thumbnailLink($image['image_path'],120,120).'" alt="some image name..." />'; // remember to always use an alt tag for images
            echo "</li>";
        }
        echo "<br class='clear'/>";
        echo "</ul>";
        echo "</td><td width='39'>";
        echo "</td></tr></table>";
        echo "</div>";
        echo "<br class='clear' />";


        echo dispPages ($total,$perPage,$currentPage,'id='.$galleryId);
    }

    #get photos portfolio
    function get_gallery_images(){
        $id=trime($_GET['id']);
        $p=trime($_GET['p']);
        $PageSize=2;
        $strSQL="SELECT * FROM media WHERE gallery=".sqlencode($id);
        $objRS=mysql_query($strSQL);
        $total=mysql_num_rows($objRS);
        $strSQL=makePages($strSQL,$PageSize,$p);
        $objRS=mysql_query($strSQL);


        echo "<div style='float:right;'>";

        $gallery_name=getfield($id,"name","gallery");
        echo "<h3 style='text-indent:40px;'>".$gallery_name."</h3>";

        echo "<table width='578'><tr><td width='39'>";
        //echo dispPagesB ($total,$PageSize,$p,'id='.$id);
        echo "</td><td width='500'>";
        echo "<ul style='width:510px; height:500px;'>";
        while($row=mysql_fetch_object($objRS)):
            echo "<li style='float:left; margin-right:2px; margin-left:2px;'>";

            //echo "<img src='".$row->image."'/>";
            echo gd_image($row->image,"cropratio=1:1&width=121&height=121");

            echo "</li>";
            endwhile;
        echo "<br class='clear'/>";
        echo "</ul>";

        echo "</td><td width='39'>";
        //echo dispPagesF ($total,$PageSize,$p,'id='.$id);
        echo "</td></tr></table>";
        echo "</div>";
        echo "<br class='clear' />";
        echo dispPages ($total,$PageSize,$p,'id='.$id);
        //echo dispPagesAll ($total,$PageSize,$p,'id='.$id);

    }

    #get photos portfolio
    function get_gallery_images_xx(){
        $id=trime($_GET['id']);
        $p=trime($_GET['p']);
        $PageSize=2;

        $table = new Table('menu');
        $strSQL="SELECT * FROM media WHERE gallery=".sqlencode($id);
        $objRS=mysql_query($strSQL);
        $total=mysql_num_rows($objRS);
        $strSQL=makePages($strSQL,$PageSize,$p);
        $objRS=mysql_query($strSQL);



        echo "<div style='float:right;'>";

        $gallery_name=getfield($id,"name","gallery");
        echo "<h3 style='text-indent:40px;'>".$gallery_name."</h3>";

        echo "<table width='578'><tr><td width='39'>";
        //echo dispPagesB ($total,$PageSize,$p,'id='.$id);
        echo "</td><td width='500'>";
        echo "<ul style='width:510px; height:500px;'>";
        while($row=mysql_fetch_object($objRS)):
            echo "<li style='float:left; margin-right:2px; margin-left:2px;'>";

            //echo "<img src='".$row->image."'/>";
            echo gd_image($row->image,"cropratio=1:1&width=121&height=121");

            echo "</li>";
            endwhile;
        echo "<br class='clear'/>";
        echo "</ul>";

        echo "</td><td width='39'>";
        //echo dispPagesF ($total,$PageSize,$p,'id='.$id);
        echo "</td></tr></table>";
        echo "</div>";
        echo "<br class='clear' />";
        echo dispPages ($total,$PageSize,$p,'id='.$id);
        //echo dispPagesAll ($total,$PageSize,$p,'id='.$id);

    }




    function get_gallery_images_x(){
        global $_GET;

        $id=trime($_GET['id']);
        $p=trime($_GET['p']);
        $PageSize=2;

        $table = new Table("media");
        $resultArray = $table->findWhere("active=1 and gallery=$id");

        $objRS=mysql_query($resultArray);
        $total=mysql_num_rows($objRS);
        $resultArray=makePages($resultArray,$PageSize,$p);
        $objRS=mysql_query($resultArray);


        $gallery_name=getfield($id,"name","gallery"); echo "<h3 style='text-indent:40px;'>".$gallery_name."</h3>";

        foreach($resultArray as $mediaItem){
            echo"<img src='".$mediaItem['image']."'/>";
        }
        echo dispPages ($total,$PageSize,$p,'id='.$id);
    }


?>