Change references to numeric child/parent IDs which can now be text
[contractdashboard.git] / cutenews / inc / massactions.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
<?PHP

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Mass Delete
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
if($action == "mass_delete"){

if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }

echoheader("options", "Delete News");
echo "<form method=post action=\"$PHP_SELF\"><table border=0 cellpading=0 cellspacing=0 width=100% height=100%><tr><td >
Are you sure you want to delete all selected news (<b>".count($selected_news)."</b>) ?<br><br>
<input type=button value=\" No \" onclick=\"javascript:document.location='$PHP_SELF?mod=editnews&action=list&source=$source'\"> &nbsp; <input type=submit value=\"   Yes   \">
<input type=hidden name=action value=\"do_mass_delete\">
<input type=hidden name=mod value=\"massactions\">
<input type=hidden name=source value=\"$source\">";
foreach($selected_news as $newsid){
        echo "<input type=hidden name=selected_news[] value=\"$newsid\">\n";
}
echo "</td></tr></table></form>";

echofooter();
exit;

}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Do Mass Delete
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "do_mass_delete"){
if(!$selected_news){ msg("error", "Error", "You have not specified any articles to be deleted", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source == ""){ $news_file = "data/news.txt"; $comm_file = "data/comments.txt";}
elseif($source == "postponed"){ $news_file = "data/postponed_news.txt"; $comm_file = "data/comments.txt"; }
elseif($source == "unapproved"){ $news_file = "data/unapproved_news.txt"; $comm_file = "data/comments.txt"; }
else{ $news_file = "./data/archives/$source.news.arch"; $comm_file = "./data/archives/$source.comments.arch"; }

$deleted_articles = 0;

// Delete News
        $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(@!in_array($old_db_arr[0], $selected_news)){
                        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){ fwrite($new_db,"$old_db_line"); }
                else{$deleted_articles ++;}
                        }
        }
        fclose($new_db);

// Delete Comments
        $old_db = file("$comm_file");
        $new_db = fopen("$comm_file", w);
        foreach($old_db as $old_db_line){
                $old_db_arr = explode("|", $old_db_line);
                if(@!in_array($old_db_arr[0], $selected_news)){
                        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){ fwrite($new_db,"$old_db_line"); }
                else{ /* Do Nothing => Delete :) */ }
                        }
        }
        fclose($new_db);


if(count($selected_news) == $deleted_articles){ msg("info", "Deleted News", "All articles that you selected (<b>$deleted_articles</b>) were deleted", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
else{ msg("error", "Deleted News (some errors occured !!!)", "$deleted_articles of ".count($selected_news)." articles that you selected were deleted", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Mass Approve
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "mass_approve"){
if($member_db[1] != 1 and $member_db[1] != 2){ msg("error", "Error", "You do not have permissions for this action.", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
$news_file = "./data/unapproved_news.txt";

        $approved_articles = 0;
        $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(@!in_array($old_db_arr[0], $selected_news)){
                        fwrite($new_db,"$old_db_line");
                }
                else
                {
                //Move the article to Active News

                         $all_active_db = file("$cutepath/data/news.txt");
                         $active_news_file = fopen("$cutepath/data/news.txt", "w");
                         @flock ($active_news_file,2);

                         fwrite($active_news_file,"$old_db_line");
                         foreach ($all_active_db as $active_line){ fwrite($active_news_file, "$active_line");}
                         @flock ($active_news_file,3);
                         fclose($active_news_file);
                         $approved_articles++;
                }
        }
        fclose($new_db);
if(count($selected_news) == $approved_articles){ msg("info", "News Approved", "All articles that you selected ($approved_articles) were approved and are now active", "$PHP_SELF?mod=editnews&action=list"); }
else{ msg("error", "News Approved (with errors)", "$approved_articles of ".count($selected_news)." articles that you selected were approved", "$PHP_SELF?mod=editnews&action=list"); }

exit;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Mass Move to Cat
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "mass_move_to_cat"){

if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }

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

        }


echoheader("options", "Move Articles to Category");

echo "<form action=\"$PHP_SELF\" method=post><table border=0 cellpading=0 cellspacing=0 width=100% height=100%><tr><td >Move selected articles (<b>".count($selected_news)."</b>) to category:";


    echo'<table width="80%" border="0" cellspacing="0" cellpadding="0" class="panel">';

    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]}'>
        <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>";


echo "</table>";



foreach($selected_news as $newsid){
        echo "<input type=hidden name=selected_news[] value=\"$newsid\">";
}

echo "<br><input type=hidden name=action value=\"do_mass_move_to_cat\"><input type=hidden name=source value=\"$source\"><input type=hidden name=mod value=\"massactions\">&nbsp;<input type=submit value=\"Move\"></td></tr></table></form>";

echofooter();
exit;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DO Mass Move to One Category
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "do_mass_move_to_cat"){

if($member_db[1] != 1){ msg("error", "Error", "You do not have permissions for this action.", "$PHP_SELF?mod=editnews&action=list&source=$source"); }

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


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

        }


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

    $nice_category = '';
    $ccount = 0;

    foreach($category as $ckey=>$cvalue){
            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.
   $nice_category = $category;
}

if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source == ""){ $news_file = "./data/news.txt";}
elseif($source == "postponed"){ $news_file = "data/postponed_news.txt"; }
elseif($source == "unapproved"){ $news_file = "data/unapproved_news.txt"; }
else{ $news_file = "./data/archives/$source.news.arch"; }
        $moved_articles = 0;
        $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(@!in_array($old_db_arr[0], $selected_news)){
                        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){ fwrite($new_db,"$old_db_line"); }
                else{

                        fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$old_db_arr[2]|$old_db_arr[3]|$old_db_arr[4]|$old_db_arr[5]|$nice_category|||\n");
                        $moved_articles ++;
                }
                        }
        }
        fclose($new_db);
if(count($selected_news) == $moved_articles){ msg("info", "News Moved", "All articles that you selected ($moved_articles) were moved to the specified category", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
else{ msg("error", "News Moved (with errors)", "$moved_articles of ".count($selected_news)." articles that you selected were moved to the specified category", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Mass Archive
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "mass_archive"){
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source != ""){ msg("error", "Error", "These news are already archived or are in postpone queue", "$PHP_SELF?mod=editnews&action=list&source=$source"); }

echoheader("options", "Send News To Archive");

echo "<form method=post action=\"$PHP_SELF\"><table border=0 cellpading=0 cellspacing=0 width=100% height=100%><tr><td >
Are you sure you want to send all selected news (<b>".count($selected_news)."</b>) to the archive ?<br><br>
<input type=button value=\" No \" onclick=\"javascript:document.location='$PHP_SELF?mod=editnews&action=list&source=$source'\"> &nbsp; <input type=submit value=\"   Yes   \">
<input type=hidden name=action value=\"do_mass_archive\">
<input type=hidden name=mod value=\"massactions\">";
foreach($selected_news as $newsid){
        echo"<input type=hidden name=selected_news[] value=\"$newsid\">\n";
}
echo"</td></tr></table></form>";

echofooter();
exit;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DO Mass Send To Archive
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "do_mass_archive"){
if($member_db[1] != 1){ msg("error", "Access Denied", "You can not perfor this action if you are not admin"); }
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if(!is_writable("./data/archives/")){ msg("error", "Error", "The ./data/archives/ directory is not writable, CHMOD it to 777"); }
$news_file = "./data/news.txt";
$comm_file = "./data/comments.txt";

    $prepeared_for_archive = array();
    $prepeared_comments_for_archive = array();
        $archived_news = 0;

// Prepear the news for Archiving

        $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(@!in_array($old_db_arr[0], $selected_news)){
                        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  ){  fwrite($new_db,"$old_db_line");  }
                else{
                    $prepeared_news_for_archive[] = $old_db_line;
                    $archived_news++;
                }
                        }
        }
        fclose($new_db);

    if($archived_news == 0){ msg("error", "Error", "No news were found for archiving."); }

// Prepear the comments for Archiving

        $old_db = file("$comm_file");
        $new_db = fopen("$comm_file", w);
        foreach($old_db as $old_db_line){
                $old_db_arr = explode("|", $old_db_line);
                if(@!in_array($old_db_arr[0], $selected_news)){
                        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){ fwrite($new_db,"$old_db_line"); }
                else{
                    $prepeared_comments_for_archive[] = $old_db_line;
                }
                        }
        }
        fclose($new_db);

// Start Archiving

$arch_name = time()+($config_date_adjust*60);

        $arch_news = fopen("./data/archives/$arch_name.news.arch", w);
    foreach($prepeared_news_for_archive as $item){
                fwrite($arch_news, "$item");
    }
    fclose($arch_news);

        $arch_comm = fopen("./data/archives/$arch_name.comments.arch", w);
    foreach($prepeared_comments_for_archive as $item){
                fwrite($arch_comm, "$item");
    }
    fclose($arch_comm);

msg("info", "News Archived", "All articles that you selected ($archived_news) are now archived under ./data/archives/<b>$arch_name</b>.news.arch", "$PHP_SELF?mod=editnews&action=list&source=$source");
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  If No Action Is Choosed
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
else{

msg("info", "Choose Action", "Please choose action from the drop-down menu", "$PHP_SELF?mod=editnews&action=list&source=$source");

}
?>