Remove cutenews/yui, use twitter bootstrap css
[contractdashboard.git] / addnews.mdu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<?PHP

if($member_db[1] > 3){ msg("error", "Access Denied", "You don't have permission to add news"); }

    $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);
              if($member_db[1] <= $ocat_arr[3] or ($ocat_arr[3] == '0' || $ocat_arr[3] == '')){
                 $cat_lines[] = $single_line;
                 $allowed_cats[] = $ocat_arr[0];
              }

        }

if ($action == "addnews"){






        echoheader("addnews", "Add News");


    $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 > Convert new lines to &lt;br /&gt;</label>
    <br/>
    <label for='html'>
     <input id='html' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"dummi\" checked disabled> Use HTML in this article</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 > Convert new lines to &lt;br /&gt;</label>
    <br/>
    <label for='html'>
     <input id='html' style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_use_html\" checked> Use HTML in this article</label>
    <br/>";
    }

    echo "
    <SCRIPT LANGUAGE=\"JavaScript\">
    function preview(){
             if(document.addnews.short_story.value == '' || document.addnews.title.value == ''){ alert('Your article must have at least Title and Short Story'); }
             else{
                  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='addnews';document.addnews.target='_self'\",500)
             }
    }

    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;
}

    function increaseTextareaBug(){";

     if($use_wysiwyg){
             echo"var area = '$full_story_id';
             if (document.getElementById(area).style.height == '') {
                 document.getElementById(area).style.height = '250px';
             }
             else{
                  var pattern = new RegExp(\"\\\\d+\",'ig');
                  var currHeight = document.getElementById(area).style.height.match(pattern);
                  var newHeight = +currHeight + 1;
                  document.getElementById(area).style.height = newHeight + 'px';
             }";
             }

    echo"}

    onload=focus;function focus(){document.forms[0].title.focus();}

    </SCRIPT>

<form onSubmit = \"return submitForm();\"  method=post name=addnews action=\"$PHP_SELF\">
        <table border=0 cellpading=0 cellspacing=0 width=\"654\" >

    <tr>
        <td width=\"75\">
        Title
        <td width=\"575\" colspan=\"2\">
        <input type=text size=\"55\" name=\"title\" tabindex=1>
        </tr>";

        if($config_use_avatar == "yes"){
            echo"<tr>
                <td width=\"75\">
                Avatar URL
                <td width=\"575\" colspan=\"2\">
                <input tabindex=2 type=text size=\"42\" value=\"$member_db[8]\" name=\"manual_avatar\" >&nbsp;&nbsp;&nbsp;<font style=\"font-size:7pt\">(optional)</font>
                </tr>";
        }
/* Old Single Category Code  */

        if(count($cat_lines) > 0){
                echo"<tr id='singlecat'>
                <td width=\"75\">
                Category
                <td width=\"575\" colspan=\"2\">
                <select id='selecsinglecat' name=category tabindex=3>\n
        <option value=\"\"> </option>\n";
                foreach($cat_lines as $single_line){
                                $cat_arr = explode("|", $single_line);
                $if_is_selected = "";
                if($category == $cat_arr[0]){ $if_is_selected = " selected "; }
                echo"<option $if_is_selected value=\"$cat_arr[0]\">$cat_arr[1]</option>\n";
                    }
            echo"</select> <a href=\"javascript:ShowOrHide('multicat','singlecat');\" onClick=\"javascript:document.getElementById('selecsinglecat').name='';\">(multiple categories)</a></tr>";
        }


/*###
##### New Multy Category Code
*/###



        if(count($cat_lines) > 0){
                echo"
                <tr style=\"display:none;\" id='multicat'>
                <td width=\"75\">
                Category
                <td>";
                echo'<table width="100%" border="0" cellspacing="0" cellpadding="0" class="panel">';

                foreach($cat_lines as $single_line){


                $cat_arr = explode("|", $single_line);
                $if_is_selected = "";
                if($category == $cat_arr[0]){ $if_is_selected = " checked "; }

  //              echo"<input name='category[]' type=checkbox $if_is_selected value=\"$cat_arr[0]\">$cat_arr[1],\n";

        echo"

        <td style='font-size:10px;' valign=top>
        <label for='cat{$cat_arr[0]}'>
        <input $if_is_selected 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></table> <td> </td>  ";
        }









  echo"
    <tr>
        <td width=\"75\" valign=\"top\">
        <br />Short Story
        <td>";


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', '', 460, 250, true, false);
</script>
        ";
}else{
     echo"
     <textarea rows=\"12\" cols=\"74\" id=\"short_story\" name=\"short_story\" tabindex=4></textarea>
     ";
}

     echo"
        <td width=\"108\" valign=\"top\" 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 />
        [insert image]</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\">[quick tags]</a><br /> -->
        <a href=# onclick=\"increaseTextarea('$short_story_id'); return false;\">[expand]</a>
        <br /><br />

        ";

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

    echo"
    </tr>

    <tr id='full-story' style='display:none;z-index:1;'>
        <td width=\"75\" valign=\"top\">
        <br />Full Story<br /><font style=\"font-size:7pt\">(optional)</font>
        <td>
        ";


if ($use_wysiwyg) {
    echo"<script language=\"JavaScript\" type=\"text/javascript\">
        writeRichText('full_story', '', 460, 300, true, false);
        </script>";
}else{
      echo"<textarea rows=\"12\" cols=\"74\" id=\"full_story\" name=\"full_story\" tabindex=5></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\">[insert image]</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\">[quick tags]</a><br />-->

        <a href=# onclick=\"increaseTextarea('$full_story_id'); return false;\">[expand]</a>
        <br /><br />
        ";

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

        echo"
    </tr>

        <tr>
        <td>
        <td>



     <table border=0 cellspacing=0 cellpadding=0 width=100%>
      <tr>
       <td width=50%>
        <input type=submit style='font-weight:bold' title=\"Post the New Article\" value=\"     Add News     \" accesskey=\"s\">
       </td>
       <td width=50% align=right>
        <input style='width:110px;'type=button onClick=\"ShowOrHide('full-story',''); setTimeout('increaseTextareaBug()',310);\" value=\"Toggle Full-Story\"> <input style='width:90px;' type=button onClick=\"ShowOrHide('options','');\" value=\"Article Options\">
       </td>
      </tr>
    </table>

        </tr>

        <tr id='options' style='display:none;'>
        <td width=\"75\"><br>Options
        <td width=\"575\" colspan=\"4\">
    <br>

    $article_format_options

   <label for='active'><input CHECKED id='active' style=\"border:0; background-color:transparent\" type=radio value=\"active\" name=\"postpone_draft\">
    <b>Normal</b>, add article as active</label>
    <br />

     <label for='draft'><input id='draft' style=\"border:0; background-color:transparent\" type=radio value=\"draft\" name=\"postpone_draft\">
    <b>Draft</b>, add article as unapproved</label>
    <br />

    <label for='postpone'><input id='postpone' style=\"border:0; background-color:transparent\" type=radio value=\"postpone\" name=\"postpone_draft\">
    <b>Postpone</b>, make article active at</label>


       <select name=from_date_day>";


for($i=1;$i<32;$i++){
    if(date("j") == $i){ echo"<option selected value=$i>$i</option> \n"; }
   else{ echo"<option value=$i>$i</option> \n"; }
}

echo"</select> \n <select name=from_date_month> \n";

for($i=1;$i<13;$i++){
    $timestamp = mktime(0,0,0,$i,1,2003);
    if(date("n") == $i){ echo"<option selected value=$i>". date("M", $timestamp) ."</option> \n"; }
    else{ echo"<option value=$i>". date("M", $timestamp) ."</option> \n"; }
}

echo"</select> \n <select name=from_date_year>";

for($i=2005;$i<2011;$i++){
    if(date("Y") == $i){ echo"<option selected value=$i>$i</option> \n"; }
    else{ echo"<option value=$i>$i</option> \n"; }
}

    $date_hour = date("H");
    $date_minutes = date("i");
    echo"
    </select>

    @ <input value='$date_hour' title='24 Hour format [hh]' name=from_date_hour size=2 type=text /> : <input value='$date_minutes' title='Minutes [mm]' name=from_date_minutes size=2 type=text />



    </tr>

    <input type=hidden name=mod value=addnews>
        <input type=hidden name=action value=doaddnews>

        </table></form>";

    echofooter();
}
// ********************************************************************************
// Do add News to news.txt
// ********************************************************************************

elseif($action == "doaddnews")
{

/////
///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{ //Single or Not category
   //don't format $nice_cats because we have not selected any.
   if( $category !="" and isset($category) and !in_array($category,$allowed_cats) ){ die('not allowed category'); }
   $nice_category = $category;

}

// die($nice_category);


    if($member_db[1] == 3 or $postpone_draft == "draft"){
            //if the user is Journalist, add the article as unapproved
             $decide_news_file = "./data/unapproved_news.txt";
             $added_time = time()+ ($config_date_adjust*60);
             $postpone = FALSE;
             $unapproved_status_msg = "The article was marked as Unapproved!";
    }
    elseif($postpone_draft == "postpone"){

             if( !ereg("^[[:digit:]]{1,}$", $from_date_hour) or !ereg("^[[:digit:]]{1,}$", $from_date_minutes)  ){ msg("error","Error !!!","You want to add a postponed article, but the hour format is invalid.", "javascript:history.go(-1)"); }
             $postpone = TRUE;
             $added_time = mktime($from_date_hour,$from_date_minutes,0,$from_date_month,$from_date_day,$from_date_year) + ($config_date_adjust*60);
             $decide_news_file = "./data/postponed_news.txt";

    }
    else{
             $postpone = FALSE;
             $added_time = time()+ ($config_date_adjust*60);
             $decide_news_file = "./data/news.txt";
    }



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

        $full_story  = replace_news("add", $full_story, $n_to_br, $use_html);
        $short_story = replace_news("add", $short_story, $n_to_br, $use_html);
//        $title       = replace_news("add", $title, TRUE, $use_html);
        $title       = replace_news("add", $title, TRUE, FALSE); // HTML in title is not allowed

        if(trim($title) == "" or !$title){ msg("error","Error !!!","The title can not be blank.", "javascript:history.go(-1)"); }
        if(trim($short_story) == "" or !$short_story){ msg("error","Error !!!","The story can not be blank.", "javascript:history.go(-1)"); }


    if($member_db[7] == 1){ $added_by_email = $member_db[5]; }
    else{ $added_by_email = "none"; }


// Save The News Article In Active_News_File

        $all_db = file("$decide_news_file");

    foreach($all_db as $news_line){
            $news_arr = explode("|", $news_line);
            if($news_arr[0] == $added_time){ $added_time++; }
    }

        $news_file = fopen("$decide_news_file", "w");
        fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$nice_category||\n");
        foreach ($all_db as $line){ fwrite($news_file, "$line");}
        fclose($news_file);

// Add Blank Comment In The Active_Comments_File
        $old_com_db = file("./data/comments.txt");
        $new_com_db = fopen("./data/comments.txt", "w");
        fwrite($new_com_db, "$added_time|>|\n");
        foreach ($old_com_db as $line){ fwrite($new_com_db, "$line");}
        fclose($new_com_db);

// Incrase By 1 The Number of Written News for Current User
    $old_user_db = file("./data/users.db.php");
    $new_user_db = fopen("./data/users.db.php", w);
    foreach($old_user_db as $old_user_db_line){
            $old_user_db_arr = explode("|", $old_user_db_line);
            if($username!=$old_user_db_arr[2]){
                fwrite($new_user_db,"$old_user_db_line");
        }
        else
        {
                $countplus = $old_user_db_arr[6]+1;
                fwrite($new_user_db,"$old_user_db_arr[0]|$old_user_db_arr[1]|$old_user_db_arr[2]|$old_user_db_arr[3]|$old_user_db_arr[4]|$old_user_db_arr[5]|$countplus|$old_user_db_arr[7]|$old_user_db_arr[8]|$old_user_db_arr[9]||\n");
        }
    }
    fclose($new_user_db);

if($member_db[1] == 3){
//user is journalist and the article needs to be approved, Notify !!!

    if($config_notify_unapproved == "yes" and $config_notify_status == "active"){
       send_mail("$config_notify_email", "CuteNews - Unapproved article was Added", "The user $member_db[2] (journalist) posted article '$title' which needs first to be Approved.");
    }
}

    if($postpone){
        msg("info","News added (Postponed)", "The news item was successfully added to the database as postponed.<br/>It will be activated at ".date("r",$added_time));
    }
    else{
        msg("info","News added", "The news item was successfully added.</br>$unapproved_status_msg");
    }


}
?>