<?PHP

if($member_db[1] > 3){ msg("error", "Hozzáférés letiltva!", "Nincs jogod a híreket szerkeszteni."); }




    $orig_cat_lines = file("./data/category.db.php");
    //only show allowed categories
        $allowed_cats = array();
        $cat_lines = array();
        foreach($orig_cat_lines as $single_line){
                  $ocat_arr = explode("|", $single_line);
                 $cat[$ocat_arr[0]] = $ocat_arr[1];
              if($member_db[1] <= $ocat_arr[3] or ($ocat_arr[3] == '0' || $ocat_arr[3] == '')){
                 $cat_lines[] = $single_line;
                 $allowed_cats[] = $ocat_arr[0];
              }

        }




// ********************************************************************************
// List all news available for editing
// ********************************************************************************
if($action == "list")
{
        echoheader("editnews","Szerkesztés");







    // How Many News to show on one page
    if($news_per_page == ""){ $news_per_page = 21; }

    $all_db = array();
    if($source == ""){ $all_db = file("./data/news.txt"); }
    elseif($source == "postponed"){ $all_db = file("./data/postponed_news.txt"); ResynchronizePostponed(); }
    elseif($source == "unapproved"){ $all_db = file("./data/unapproved_news.txt");}
    else{ $all_db = file("./data/archives/${source}.news.arch"); }



// choose only needed news items
if ($category != '' or $author != "" or $member_db[1] == 3){
        foreach($all_db as $raw_line){
                $raw_arr = explode("|", $raw_line);

                 ;

        if (
                 ($category == '' or in_array($category, explode(',',$raw_arr[6])))
             and ($author == "" or $raw_arr[1] == $author)
             and ($member_db[1] != 3 or $raw_arr[1] == $member_db[2] )

           ){
                         $all_db_tmp[] = $raw_line;
        }
    }
$all_db = $all_db_tmp;
}


// Prelist Entries
    $flag = 1;
        if($start_from == "0"){ $start_from = ""; }
    $i = $start_from;
    $entries_showed = 0;

if(!empty($all_db)){

    foreach ($all_db as $line){
        if($j < $start_from){ $j++; continue; }
        $i++;

        $item_db = explode("|",$line);
             $itemdate = date("d/m/y",$item_db[0]);

                     if($flag == 1){ $bg="#F7F6F4"; $flag = 0; }
                     else {$bg = "#FFFFFF"; $flag = 1;}

                     if(strlen($item_db[2]) > 74){ $title = substr($item_db[2],0,70)." ..."; }
            $title = stripslashes( preg_replace(array("'\|'", "'\"'", "'\''"), array("I", "&quot;", "&#039;"), $item_db[2]) );
            $title = ereg_replace("<[^>]*>","",$title);
                     $entries .= "<tr>

                <td height=18  bgcolor=$bg>
                 <!-- ID: $item_db[0]--><a title='EDIT: $item_db[2]' href=\"$PHP_SELF?mod=editnews&action=editnews&id=$item_db[0]&source=$source\">$title</a>
                 <td height=18 bgcolor=$bg align=right>";
             $count_comments = countComments($item_db[0], $source);
             if($count_comments == 0){$entries .= "<font color=gray>$count_comments</font>";}
             else{$entries .= "$count_comments";}

             $entries .= "&nbsp;&nbsp;&nbsp;&nbsp;<td height=18 bgcolor=$bg nowrap>&nbsp;&nbsp;&nbsp;";


             if($item_db[6] == ""){ $my_cat = "<font color=gray>---</font>"; }

//             elseif($cat[$item_db[6]] == ""){ $my_cat = "<font color=red title='A hír olyan kategóriához volt hozzáadva, ami már nem létezik.'>(ID: <b>$item_db[6]</b>)</font>"; }

             elseif(strstr($item_db[6],',')){
                     $all_this_cats_arr = explode(',',$item_db[6]);
                     $my_multy_cat_labels = '';
                     foreach($all_this_cats_arr as $this_single_cat){
                             $my_multy_cat_labels .= "$cat[$this_single_cat], ";
                     }
                     $my_cat = "<span onmouseover=\" window.status='categories: $my_multy_cat_labels'; return true\" onmouseout=\"window.status=''; return true\"><font color=#7979FF title='$my_multy_cat_labels'>(több)</font></span>";
             }

             else{ $my_cat = $cat[$item_db[6]]; }

             $entries .= "$my_cat&nbsp;<td height=18 bgcolor=$bg>
                 $itemdate
                 <td height=18 bgcolor=$bg>
                       $item_db[1]

                       <td align=center bgcolor=$bg><input name=\"selected_news[]\" value=\"{$item_db[0]}\" style=\"border:0; background-color:$bg\" type='checkbox'>

             </tr>
            ";
                $entries_showed ++;

            if($i >= $news_per_page + $start_from){ break; }
    }//foreach news line
}
// End prelisting



    $all_count_news = count($all_db);
    if($category != ""){ $cat_msg = "Kategória: <b>$cat[$category]</b>;"; }

    if($source == "postponed"){ $source_msg = "<span style='background-color:yellow;'>Halasztott hírek, <a title='Halasztott hír frissítése' href=\"$PHP_SELF?mod=editnews&action=list&source=postponed\">[Újraszinkronizálás]</a></span>"; $postponed_selected = " selected ";}
    elseif($source == "unapproved"){ $source_msg = "<span style='background-color:yellow;'>Jóváhagyatlan hírek</span>"; $unapproved_selected = " selected ";}
    elseif($source != "" ){

                $news_lines = file("./data/archives/$source.news.arch");
                $count = count($news_lines);
                $last = $count-1;
                $first_news_arr = explode("|", $news_lines[$last]);
                $last_news_arr        = explode("|", $news_lines[0]);
                $first_timestamp = $first_news_arr[0];
                $last_timestamp         = $last_news_arr[0];
                $source_msg = "Archive: <b>". date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp) ."</b>;";
        }



///////////////////////////////////////////
// Options Bar
echo"
        <table class=panel  border=0 cellpading=0 cellspacing=0 width=99% >
        <tr>
          <td title='További opciók' style=\"cursor:pointer;\" onClick=\"getElementById('options').style.display='';\">
         <b>$entries_showed</b> / <b>$all_count_news</b> hír; $cat_msg $source_msg
          </td>

          <td >
        <p align=\"right\"><a href=\"javascript:ShowOrHide('options','')\">további opciók&nbsp;</a>
          </td>
        </tr>
    <tr>
          <td colspan=\"2\" >


<div id='options' style='display:none;z-index:1;' >
<form action=\"$PHP_SELF?mod=editnews&action=list\" method=POST name=options_bar>
<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
        <td height=\"1\" style=\"border-top: 1px dashed silver\" width=\"100%\" align=\"right\" colspan=\"3\">
    <p align=\"center\">&nbsp;
        </td>
</tr>
<tr >
        <td height=\"1\" width=\"286\" align=\"right\">
    Forrás&nbsp;
        </td>
        <td height=\"1\" width=\"180\">
<select name=\"source\" size=\"1\"><option value=\"\">- Aktív hírek -</option> \n <option $postponed_selected value=\"postponed\">- Halasztott hírek -</option> \n <option $unapproved_selected value=\"unapproved\">- Jóváhagyatlan hírek -</option>";

        if(!$handle = opendir("./data/archives")){ die("<center>A ./data/archives könyvtárt nem lehet megnyitni. "); }
                   while (false !== ($file = readdir($handle)))
           {
                           if($file != "." and $file != ".." and !is_dir("./data/archives/$file") and eregi("news.arch", $file))
            {
                    $file_arr = explode(".", $file);
                $id                  = $file_arr[0];

                $news_lines = file("./data/archives/$file");
                $count = count($news_lines);
                $last = $count-1;
                $first_news_arr = explode("|", $news_lines[$last]);
                $last_news_arr        = explode("|", $news_lines[0]);

                $first_timestamp = $first_news_arr[0];
                $last_timestamp         = $last_news_arr[0];

                                $arch_date = date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp);
                $ifselected = "";
                if($source == $file_arr[0]){ $ifselected = "selected"; }
                echo "<option $ifselected value=\"$file_arr[0]\">Archive: $arch_date ($count)</option>";
                           }
                   }
        closedir($handle);

echo"</select>

        </td>
        <td height=\"1\" width=\"182\">
        </td>
</tr>
<tr>
        <td height=\"1\" width=\"284\" align=\"right\" >
    Kategória&nbsp;
        </td>
        <td height=\"1\" width=\"178\" >
    <select name=\"category\" ><option selected value=\"\">- Mindegyik -</option>";

    //$cat_lines = file("./data/category.db.php");  commented-out because can lines are already opened before, and filtered with propper restrictions for user

        foreach($cat_lines as $single_line){
                $cat_arr = explode("|", $single_line);
                $ifselected = "";
                if($category == $cat_arr[0]){ $ifselected = "selected"; }
        echo"<option $ifselected value=\"$cat_arr[0]\">$cat_arr[1]</option>\n";
           }

    echo"</select>

        </td>
        <td height=\"1\" width=\"180\" >
        </td>
</tr>
";

if($member_db[1] != 3){
echo"
<tr>
        <td height=\"1\" width=\"284\" align=\"right\" >
    Szerkesztő&nbsp;
        </td>
        <td height=\"1\" width=\"178\" >
    <select name=author size=\"1\"><option value=\"\">- Mindegy -</option>";
    $user_lines = file("./data/users.db.php");
        foreach($user_lines as $single_line){
        if(!eregi("<\?", $single_line)){
                $user_arr = explode("|", $single_line);
                    $ifselected = "";
            if($user_arr[1] != 4){
                    if($author == $user_arr[2]){ $ifselected = "selected"; }
                        echo"<option $ifselected value=\"$user_arr[2]\">$user_arr[2]</option>\n";
                        }
                }
           }
    echo"</select>
        </td>
        <td height=\"1\" width=\"180\" >
        </td>
</tr>
";
}

echo"
<tr>
<td height=\"1\" width=\"284\" align=\"right\" >
Hírek oldalaként&nbsp;
</td>
<td height=\"1\" width=\"178\" >
<input style=\"text-align: Center\" name=\"news_per_page\" value=\"$news_per_page\" type=text size=3>
</td>
<td height=\"1\" width=\"180\" >
</td>
</tr>


<tr>
        <td height=\"1\" width=\"284\" align=\"right\" >
        </td>
        <td height=\"1\" width=\"178\" >
    <br><input type=submit value=\"Keresés\">
        </td>
        <td height=\"1\" width=\"180\" >
        </td>
</tr>
</table>
</form>
</div>
          </td>
    </tr>
        </table>&nbsp;";

// End Options Bar
////////////////////////////////////////////////////////////////////////////////    Showing List of News
if($entries_showed == 0){
    echo"<table border=0 cellpading=0 cellspacing=0 width=100% >
        <form method=post name=editnews>
        <td colspan=6 ><p style=\"border: solid black 1px;  margin: 22px 22px 22px 22px; padding: 4px 4px 4px 4px;\" align=center>- Nincs a keresési feltételeknek megfelelő találat. -<br><a href=\"#\"  onClick=\"getElementById('options').style.display='';\">[beállítások]</a></p>";
}
else{
echo<<<JSCRIPT
<script language='JavaScript' type="text/javascript">
<!--
function ckeck_uncheck_all() {
        var frm = document.editnews;
        for (var i=0;i<frm.elements.length;i++) {
                var elmnt = frm.elements[i];
                if (elmnt.type=='checkbox') {
                        if(frm.master_box.checked == true){ elmnt.checked=false; }
            else{ elmnt.checked=true; }
                }
        }
        if(frm.master_box.checked == true){ frm.master_box.checked = false; }
    else{ frm.master_box.checked = true; }
}

-->
</script>
JSCRIPT;

    echo"<table border=0 cellpading=0 cellspacing=0 width=99% >
        <form method=post name=editnews>
        <td width=347>
        Cím
        <td width=65>
        Hozzászólások

        <td width=65>
        &nbsp;Kategória

        <td width=58>
        &nbsp;Dátum

        <td width=78>
        Szerkesztő

        <td width=21 align=center> <input style=\"border: 0px; background:transparent;\" type=checkbox name=master_box title=\"Összes kijelölése\" onclick=\"javascript:ckeck_uncheck_all()\"> </a> ";
}
#####################################################################################################################
echo $entries;
#####################################################################################################################

if($start_from > 0)
{

        $previous = $start_from - $news_per_page;
        $npp_nav .= "<a href=\"$PHP_SELF?mod=editnews&action=list&start_from=$previous&category=$category&author=$author&source=$source&news_per_page=$news_per_page\"><< Előző</a>";
        $tmp = 1;
}

if(count($all_db) > $i)
{
        if($tmp){ $npp_nav .= "&nbsp;&nbsp;||&nbsp;&nbsp;";}
        $how_next = count($all_db) - $i;
        if($how_next > $news_per_page){ $how_next = $news_per_page; }
        $npp_nav .= "<a href=\"$PHP_SELF?mod=editnews&action=list&start_from=$i&category=$category&author=$author&source=$source&news_per_page=$news_per_page\">Következő $how_next >></a>";
}

if($entries_showed != 0){
echo<<<HTML
<tr>
<td colspan=7 align=right>&nbsp;
</tr>

<tr>
<td>
$npp_nav
<td colspan=7 align=right>

Művelet a kiválasztott hírekkel:
<select name=action>
<option value="">-- Válassz! --</option>
<option title="kiválasztott hírek törlése" value="mass_delete">Törlés</option>
HTML;

if($member_db[1] == 1){ echo"<option title=\"archívum készítése a kiválasztott hírekből\" value=\"mass_archive\">Archiválás</option>"; }


if( $source == "unapproved" ){ $if_mass_appr = "SELECTED"; } else {$if_mass_appr = ''; }
if( $source == "unapproved" and ($member_db[1] == 1 or $member_db[1] == 2)){ echo"<option $if_mass_appr title=\"kiválasztott hírek jóváhagyása\" value=\"mass_approve\">Jóváhagyás</option>"; }

if($member_db[1] == 1){ echo"<option title=\"kiválasztott hírek kategóriájának változtatása\" value=\"mass_move_to_cat\">Kategóriaváltás</option>"; }
echo<<<HTML

</select>
<input type=hidden name=source value="$source">
<input type=hidden name=mod value="massactions">
<input type=submit value=OK>
</tr>
HTML;
}


echo<<<HTML
</tr>
<tr>
<td  colspan=1>
</tr>
<tr>
<td colspan=6>
</tr>
</form></table>
HTML;

    echofooter();
}
// ********************************************************************************
// Edit News Article
// ********************************************************************************
elseif($action == "editnews")
{
// Show The Article for Editing


    if($source == ""){ $all_db = file("./data/news.txt"); }
    elseif($source == "postponed"){ $all_db = file("./data/postponed_news.txt"); }
    elseif($source == "unapproved"){ $all_db = file("./data/unapproved_news.txt"); }
    else{ $all_db = file("./data/archives/$source.news.arch"); }
        $found = FALSE;
        foreach ($all_db as $line)
    {
                $item_db=explode("|",$line);
                if ($id == $item_db[0]){ $found = TRUE; break;}
        }//foreach news line

        $have_perm = 0;
           if(($member_db[1] == 1) or ($member_db[1] == 2)){$have_perm = 1;}
           elseif($member_db[1] == 3 and $item_db[1] == $member_db[2]) {$have_perm = 1;}
    if(!$have_perm){ msg("error", "Nincs hozzáférésed", "Nincs hozzáférésed ehhez a művelethez!", "$PHP_SELF?mod=editnews&action=list"); }







    if(strstr($item_db[6], ',')){
       $all_these_cats = explode(',',$item_db[6]);
       foreach($all_these_cats as $all_this_cat){
               if($member_db[1] != 1 and !in_array($all_this_cat,$allowed_cats) ){ msg("error", "Hozzáférés letiltva!", "Ez a hír olyan kategóriába tartozik, amelynek szerkesztéséhez nincs jogod."); }
       }

    }
    else{
         if($member_db[1] != 1 and !in_array($item_db[6],$allowed_cats) ){ msg("error", "Hozzáférés letiltva!", "Ez a hír olyan kategóriába tartozik, amelynek szerkesztéséhez nincs jogod."); }
    }






    if (!$found){ msg("error","Hiba!!!","A kiválasztott hírt <b>nem</b> találom."); }
    $newstime   = date("D, d F Y h:i:s", $item_db[0]);
    $item_db[2] = stripslashes( preg_replace(array("'\|'", "'\"'", "'\''"), array("I", "&quot;", "&#039;"), $item_db[2]) );




       $short_story_id = 'short_story';
       $full_story_id = 'full_story';

     //
    // Are we using the WYSIWYG ?
    //
    if($config_use_wysiwyg == "yes"){
       $use_wysiwyg = true;
       $article_format_options = "
    <label for='convert'>
     <input id='convert' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_convert_new_lines\" disabled > Sortörések átalakítása &lt;br /&gt; -ré</label>
    <br/>
    <label for='html'>
     <input id='html' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"dummi\" checked disabled> HTML engedélyezése</label>
     <input type=hidden name=\"if_use_html\" value=\"yes\">
    <br/>";
    }else{
       $use_wysiwyg = false;
       $article_format_options = "
    <label for='convert'>
     <input id='convert' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_convert_new_lines\" checked > Sortörések átalakítása &lt;br /&gt; -ré</label>
    <br/>
    <label for='html'>
     <input id='html' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_use_html\" checked> HTML engedélyezése</label>
    <br/>";
    }



    $item_db[3] = replace_news("admin", $item_db[3], $use_wysiwyg);
    $item_db[4] = replace_news("admin", $item_db[4], $use_wysiwyg);


        echoheader("editnews","Szerkesztés");

    echo"
    <SCRIPT LANGUAGE=\"JavaScript\">
        function preview(){
        dd=window.open('','prv','height=400,width=750,resizable=1,scrollbars=1')
        document.addnews.mod.value='preview';document.addnews.target='prv'
        document.addnews.submit();dd.focus()
        setTimeout(\"document.addnews.mod.value='editnews';document.addnews.target='_self'\",500)
        }
    function confirmDelete(url){
        var agree=confirm(\"Biztosan törölni akarod ezt a hírt? \");
        if (agree)
        document.location=url;
        }

    function increaseTextarea(area){
             if (document.getElementById(area).style.height == '') {
                 document.getElementById(area).style.height = '300px';
             }
             else{
                  var pattern = new RegExp(\"\\\\d+\",'ig');
                  var currHeight = document.getElementById(area).style.height.match(pattern);
                  var newHeight = +currHeight + 100;
                  document.getElementById(area).style.height = newHeight + 'px';
             }


    }

function submitForm() {
        //make sure hidden and iframe values are in sync before submitting form
        //to sync only 1 rte, use updateRTE(rte)
        //to sync all rtes, use updateRTEs
        updateRTE('short_story');
        updateRTE('full_story');
        //updateRTEs();

        //change the following line to true to submit form
        return true;
}

        </SCRIPT>

    <form onSubmit = \"return submitForm();\" method=POST name=addnews action=\"$PHP_SELF\">
        <table border=0 cellpading=0 cellspacing=0 width=\"654\" height=\"100%\" >
        <td valign=middle width=\"75\">
        Info
        <td width=\"571\" colspan=\"6\">
        Elküldve: $newstime $item_db[1] által

        <tr>
        <td valign=middle width=\"75\" valign=\"top\">
        Cím
        <td width=\"464\" colspan=\"3\">
        <input type=text name=title value=\"$item_db[2]\" size=55 tabindex=1>
    <td width=\"103\" valign=\"top\">
        </tr>";

        if($config_use_avatar == "yes"){
            echo"
        <tr>
                <td valign=middle width=\"75\" valign=\"top\">
                Avatar URL
                <td width=\"464\" colspan=\"3\">
                <input type=text name=editavatar value=\"$item_db[5]\" size=42 tabindex=2>&nbsp;&nbsp;&nbsp;<font style=\"font-size:7pt\">(nem muszáj)</font>
                <td width=\"103\" valign=\"top\">
                </tr>";
        }



/* Old Single Category Code

       echo"<tr>
        <td valign=middle width=\"75\" valign=\"top\">
        Kategória
        <td width=\"464\" colspan=\"3\">
        <select name=\"category\" >";

    $cat_lines = file("./data/category.db.php");
        foreach($cat_lines as $single_line){
                $cat_arr = explode("|", $single_line);
        if($item_db[6] == $cat_arr[0]){
                        echo"<option selected=\"selected\" value=\"$cat_arr[0]\">$cat_arr[1]</option>\n";
            $selected = TRUE;
                }else{ echo"<option value=\"$cat_arr[0]\">$cat_arr[1]</option>\n"; }
        }
    if(!$selected){ echo"<option selected value=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>"; }
    else{ echo"<option value=\"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>"; }

    echo"</select>
    <td width=\"105\" valign=\"top\">

        </tr>";
*/



       echo"<tr>
        <td valign=middle width=\"75\" valign=\"top\">
        Kategória
        <td width=\"464\" colspan=\"3\">";
        echo'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="panel">';


//        $cat_lines = file("./data/category.db.php"); commented-out because can lines are already opened before, and filtered with propper restrictions for user
        foreach($cat_lines as $single_line){
                $cat_arr = explode("|", $single_line);

        echo"
        <td style='font-size:10px;' valign=top>
        <label for='cat{$cat_arr[0]}'>";

        if( in_array($cat_arr[0], explode(',',$item_db[6])) ){
            echo"<input checked style='background-color:transparent;border:0px;' type=checkbox name='category[]' id='cat{$cat_arr[0]}' value='{$cat_arr[0]}'>$cat_arr[1]</label>";
        }else{

            echo"<input style='background-color:transparent;border:0px;' type=checkbox name='category[]' id='cat{$cat_arr[0]}' value='{$cat_arr[0]}'>$cat_arr[1]</label>";
        }

        $i++;
        if ($i%4 == 0){ echo'<tr>'; }


        }
        echo"</tr>";

    echo" </table> <td> </td> </tr>";








   echo" <tr>
        <td  valign=\"top\">
        <br />Rövid hír
        <td width=\"464\" colspan=\"3\">
";

if ($use_wysiwyg) {
        echo"
        <script language=\"JavaScript\" type=\"text/javascript\" src=\"rte/richtext.js\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
        initRTE(\"rte/images/\", \"rte/\", \"rte/\", false); </script>

<script language=\"JavaScript\" type=\"text/javascript\">
        writeRichText('short_story', '".rteSafe($item_db[3])."', 460, 250, true, false);
</script>
        ";
}else{
     echo"
     <textarea rows=\"12\" cols=\"74\" id=\"short_story\" name=\"short_story\" tabindex=3>$item_db[3]</textarea>
     ";
}

     echo"

        <td width=\"165\" valign=\"top\" align=center style='background: url(skins/images/baloon.gif) no-repeat top left'>
        <p align=\"center\"><a href=# onclick=\"window.open('$PHP_SELF?&mod=images&action=quick&area=$short_story_id&wysiwyg=$use_wysiwyg', '_Addimage', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\"><br />
        [kép..]</a><br />
<!--        <a href=# onclick=\"window.open('$PHP_SELF?&mod=about&action=cutecode&target=short_story', '_CuteCode', 'HEIGHT=280,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\">[gyorskódok]</a><br /> -->
        <a href=# onclick=\"increaseTextarea('$short_story_id'); return false;\">[bővít..]</a>
        <br /><br />

";

    echo insertSmilies("$short_story_id", 4, true, "$use_wysiwyg");

        echo"</tr>

        <tr>
        <td width=\"75\" valign=\"top\">
        <br />Teljes hír<br /><font style=\"font-size:7pt\">(nem muszáj)</font>
        <td width=\"464\" colspan=\"3\">
";

if ($use_wysiwyg) {
        echo"
<script language=\"JavaScript\" type=\"text/javascript\">
        writeRichText('full_story', '".rteSafe($item_db[4])."', 460, 250, true, false);
</script>
        ";
}else{
     echo"
     <textarea rows=\"12\" cols=\"74\" id=\"full_story\" name=\"full_story\" tabindex=4>$item_db[4]</textarea>
     ";
}

     echo"

        <td width=\"108\" valign=\"top\" style='background: url(skins/images/baloon.gif) no-repeat top left'>
        <p align=\"center\"><br />
        <a href=# onclick=\"window.open('$PHP_SELF?mod=images&action=quick&area=$full_story_id&wysiwyg=$use_wysiwyg', '_Addimage', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_Addimage\">[kép..]</a><br />
<!--        <a href=# onclick=\"window.open('$PHP_SELF?&mod=about&action=cutecode&target=full_story', '_Addimage', 'HEIGHT=280,resizable=yes,scrollbars=yes,WIDTH=360');return false;\" target=\"_CuteCode\">[gyorskódok]</a><br />-->

        <a href=# onclick=\"increaseTextarea('$full_story_id'); return false;\">[bővít..]</a>
        <br /><br />";

        echo insertSmilies("$full_story_id", 4, true, "$use_wysiwyg");

        echo"</tr>
        <tr>
        <td>
        <td  colspan=\"3\">
        <input type=hidden name=id value=$id>
        <input type=hidden name=action value=doeditnews>
        <input type=hidden name=mod value=editnews>
        <input type=hidden name=source value=$source>






     <table border=0 cellspacing=0 cellpadding=0 width=100%>
      <tr>
       <td width=50%>
        <input type=submit style='font-weight:bold' value=\"Változások mentése\" accesskey=\"s\">&nbsp;
        <!--<input type=button value=\"Előnézet\" onClick=\"preview()\" accesskey=\"p\">-->
       </td>
       <td width=50% align=right>
       ";

  if($source == 'unapproved'){
     echo"<input type=button value=\"Approve\" onClick=\"javascript:document.location=('$PHP_SELF?mod=massactions&selected_news[]=$id&action=mass_approve&source=unapproved');\"> &nbsp;";
  }

  echo"<input type=button value=\"Törlés\" onClick=\"confirmDelete('$PHP_SELF?mod=editnews&action=doeditnews&source=$source&ifdelete=yes&id=$id')\"> &nbsp;
        <input style='width:90px;' type=button onClick=\"ShowOrHide('options','')\" value=\"Beállítások\">
       </td>
      </tr>
    </table>


        </tr>

        <tr id='options' style='display:none;'>
        <td width=\"75\">
    <br>Beállítások
        <td width=\"565\" colspan=\"4\">
    &nbsp;<br>
$article_format_options
        </tr>

        </form>



        <tr>
        <td width=\"75\"><br>
        <td width=\"561\" colspan=\"4\"><br>
        </tr>



        <tr>
        <td width=\"75\">
        Hozzászólások";

// Show the Comments for Editing

    if($source == "" or $source == "postponed" or $source == "unapproved"){ $all_comments_db = file("./data/comments.txt"); }
    else{ $all_comments_db = file("./data/archives/${source}.comments.arch"); }

    $found_newsid = FALSE;
        foreach($all_comments_db as $comment_line)
    {
                $comment_line = trim($comment_line);
                $comments_arr = explode("|>|",$comment_line);
        if($comments_arr[0] == $id)
        {//if these are comments for our story
            $found_newsid = TRUE;
                        if ($comments_arr[1] != "")
            {
                echo"         <td width=290>
                                <b>&nbsp;&nbsp;Író</b>, Hozzászólás előnézete

                             <td width=120>
                                <b>Dátum</b>

                              <td width=1>
                              <td width=100>
                          </tr>
                                <form method=post name=comments action=\"$PHP_SELF\">";

                $flag = 1;
                          $different_posters = explode("||",$comments_arr[1]);
                          foreach($different_posters as $individual_comment)
                          {
                            if($flag == 1){ $bg = "bgcolor=#F7F6F4"; $flag = 0;}
                        else{$bg = ""; $flag = 1;}

                            $comment_arr = explode("|",$individual_comment);
                            $comtime = date("d/m/y h:i:s",$comment_arr[0]);
                            $comm_value = stripslashes(strip_tags($comment_arr[4]));
                            $comm_excerpt_lenght = 43 - strlen($comment_arr[1]);

                            if($comm_excerpt_lenght < strlen($comm_value)){
                               $comm_excerpt = substr($comm_value,0, $comm_excerpt_lenght).'...';
                            }else{
                               $comm_excerpt = $comm_value;
                            }

                            if($comment_arr[1])
                            {
                                           if(strlen($comment_arr[1]) > 25){ $comment_arr[1] = substr($comment_arr[1],0,22)."..."; }
                                            echo"<tr>
                                           <td >
                                           <td $bg>
                                            &nbsp; <a title=\"edit this comment\nip:$comment_arr[3]\" href=\"$PHP_SELF?mod=editcomments&action=editcomment&newsid=$id&comid=$comment_arr[0]&source=$source\" onclick=\"window.open('$PHP_SELF?mod=editcomments&action=editcomment&newsid=$id&comid=$comment_arr[0]&source=$source', 'Hozzászólások', 'HEIGHT=270,resizable=yes,scrollbars=yes,WIDTH=400');return false;\">$comment_arr[1]</a>,
                                             $comm_excerpt

                                           <td $bg>
                                            <a title=\"edit this comment\nip:$comment_arr[3]\" href=\"$PHP_SELF?mod=editcomments&action=editcomment&newsid=$id&comid=$comment_arr[0]&source=$source\" onclick=\"window.open('$PHP_SELF?mod=editcomments&action=editcomment&newsid=$id&comid=$comment_arr[0]&source=$source', 'Hozzászólások', 'HEIGHT=270,resizable=yes,scrollbars=yes,WIDTH=400');return false;\">$comtime</a>
                                           <td width=\"1\" $bg>
                                            <input type=checkbox name=\"delcomid[$comment_arr[0]]\" value=1>
                                           <td $bg>
                                           </tr>";
                    }//if not blank
                          }//foreach comment

                    echo"<tr>
                    <td >
                    <td >

                    <td >
                    <p align=\"right\">mindet törlöd?
                    <td >
                    <input type=checkbox name=delcomid[all] value=1>
                    <td >
                    </tr>

                    <tr>
                    <td >
                    <td colspan=\"3\">
                    <p align=\"right\"><input type=submit value=\"Kiválasztottak törlése\">
                    <td >
                    </tr>

                    <input type=hidden name=newsid value=$id>
                    <input type=hidden name=deletecomment value=yes>
                    <input type=hidden name=action value=doeditcomment>
                    <input type=hidden name=mod value=editcomments>
                <input type=hidden name=source value=$source>
                    </form>
                    </table>";

                    break;//foreach comment line
           }//if there are any comments
           else
           {
                            echo"<td width=\"210\">
                           Nincs hozzászólás.
                           <td width=\"219\">
                           <td width=\"1\">
                           <td width=\"105\">
                           </tr>
                           </tr>
                           </table>";
           }
        }//if these are comments for our story
    }//foreach comments line
    if($found_newsid == FALSE){
            echo"<td width=\"210\">
           No Comments
           <td width=\"219\">
           <td width=\"1\">
           <td width=\"105\">
           </tr>
           </tr>
           </table>";
    }
    echofooter();
}
// ********************************************************************************
// Do Edit News
// ********************************************************************************
elseif($action == "doeditnews")
{

/////
///Format our categories variable
/////

if( is_array($category) ){  //User has selected multiple categories

    $nice_category = '';
    $ccount = 0;

    foreach($category as $ckey=>$cvalue){
            if( !in_array($cvalue,$allowed_cats) ){ die('not allowed category'); }
            if($ccount==0){ $nice_category = $cvalue; }//first cat
            else{ $nice_category = $nice_category.','.$cvalue; }

            $ccount++;
    }



}else{ //Not in a category
   if( $category !="" and isset($category) and !in_array($category,$allowed_cats) ){ die('not allowed category'); }
   //don't format $nice_cats because we have not selected any.
}

        if(trim($title) == "" and $ifdelete != "yes"){ msg("error","Hiba!!!","A cím mező nem lehet üres.", "javascript:history.go(-1)"); }
        if($short_story == "" and $ifdelete != "yes"){ msg("error","Hiba!!!","A hír mező nem lehet üres.", "javascript:history.go(-1)"); }

        if($if_convert_new_lines        == "yes"){ $n_to_br                = TRUE; }
    if($if_use_html                                == "yes"){ $use_html        = TRUE; }

        $short_story =         replace_news("add", rtrim($short_story), $n_to_br, $use_html);
        $full_story =         replace_news("add", rtrim($full_story), $n_to_br, $use_html);
        $title =                 stripslashes( preg_replace(array("'\|'", "'\n'", "''"), array("I", "<br />", ""), $title) );
    $avatar =                stripslashes( preg_replace(array("'\|'", "'\n'", "''"), array("I", "<br />", ""), $avatar) );

    if($source == ""){ $news_file = "./data/news.txt"; $com_file = "./data/comments.txt"; }
    elseif($source == "postponed"){ $news_file = "./data/postponed_news.txt"; $com_file = "./data/comments.txt"; }
    elseif($source == "unapproved"){ $news_file = "./data/unapproved_news.txt"; $com_file = "./data/comments.txt"; }
    else{ $news_file = "./data/archives/$source.news.arch"; $com_file = "./data/archives/$source.comments.arch";}

        $old_db = file("$news_file");
        $new_db = fopen("$news_file", w);
        foreach($old_db as $old_db_line){
                $old_db_arr = explode("|", $old_db_line);
                if($id != $old_db_arr[0]){
                        fwrite($new_db,"$old_db_line");
        }
        else
        {

                $have_perm = 0;
                   if(($member_db[1] == 1) or ($member_db[1] == 2)){$have_perm = 1;}
                   elseif($member_db[1] == 3 and $old_db_arr[1] == $member_db[2]) {$have_perm = 1;}
            if($have_perm){
                if($ifdelete != "yes")
            {
                    $okchanges = TRUE;
                fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$nice_category||\n");
            }
                        else
            {
                    $okdeleted = TRUE;
                                $all_file = file("$com_file");
                $new_com=fopen("$com_file","w");
                foreach($all_file as $line)
                {
                                        $line_arr = explode("|>|",$line);
                                        if($line_arr[0] == $id){ $okdelcom = TRUE; }
                    else{ fwrite($new_com,"$line"); }
                }
                fclose($new_com);
            }
                }else{ fwrite($new_db,"$old_db_line"); $no_permission = TRUE; }
        }
    }
    fclose($new_db);

    if($no_permission){ msg("error", "NO Access", "You dont have access for this action", "$PHP_SELF?mod=editnews&action=list"); }
        if($okdeleted and $okdelcom){ msg("info","Hír(ek) törölve","A hír sikeresen törölve lett.<br />A hírhez tartozó hozzászólások szintén törlésre kerültek."); }
    if($okdeleted and !$okdelcom){ msg("info","Hír(ek) törölve","A hír sikeresen törölve lett.<br />A hírhez tartozó hozzászólások szintén törlésre kerültek.<br /><font color=red>A hozzászólásokat nem sikerült törölni!!!</font>"); }
    elseif($okchanges){ msg("info","Változtatások mentve","A változtatások sikeresen el lettek mentve.", "$PHP_SELF?mod=editnews&action=editnews&id=$id&source=$source"); }
        else{ msg("error","Hiba!!!","A hír nem található, esetleg a hírt tároló fájl károsodott és nem olvasható."); }

}


?>