Remove cutenews/yui, use twitter bootstrap css
[contractdashboard.git] / tools.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

if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission for this section"); }
$success = FALSE;
// ********************************************************************************
// Archive
// ********************************************************************************
if($action == "archive")
{


               // ***************************
               // Un-Archive
               // ***************************
               if($subaction == "unarchive" and $aid != "" and isset($aid)){


                if(!$handle = opendir("$cutepath/data/archives")){ die("<center>Unable to open directory $cutepath/data/archive</center>"); }
                while (false !== ($file = readdir($handle)))
                {
                        if ($file == "$aid.news.arch")
                        {
                                $newsfile = fopen("$cutepath/data/news.txt", 'a');
                                $newsarch = file("$cutepath/data/archives/$file");
                                foreach ($newsarch as $newsline)
                                {
                                        fwrite($newsfile,$newsline);
                                }
                                fclose($newsfile);
                                unlink("$cutepath/data/archives/$file");
                        }               
                        elseif ($file == "$aid.comments.arch")
                        {
                                $commfile = fopen("$cutepath/data/comments.txt", 'a');
                                $commarch = file("$cutepath/data/archives/$file");
                                foreach ($commarch as $commline)
                                {
                                        fwrite($commfile,$commline);
                                }
                                fclose($commfile);
                                unlink("$cutepath/data/archives/$file");
                        }
                }
                closedir($handle);

               }//end Un-Archive function


        echoheader("archives", "Archives");

echo<<<HTML

    <script language="javascript">
    function confirmdelete(id,news){
            var agree=confirm("Do you really want to permanently delete this archive ?\\nAll ("+news+") news and comments in it will be deleted.");
        if (agree)
        document.location="$PHP_SELF?mod=tools&action=dodeletearchive&archive="+id;
        }
    </script>
        <form method=post action="$PHP_SELF"><table border=0 cellpading=0 cellspacing=0 width="645" >
        <td width=321 height="33">
    <b>Send news to archive</b>
<table border=0 cellpading=0 cellspacing=0 width=300  class="panel" cellpadding="10" >
    <tr>
    <td width=304 height="25">
    <p align="center">
    <input type=submit value="Proceed with archiving ...">
    </tr>

    </table>
        <input type=hidden name=action value=doarchive>
        <input type=hidden name=mod value=tools>
    </form>

        <td width=320 height="33" align="center">
       <!-- HELP -->

   <table height="25" cellspacing="0" cellpadding="0">
    <tr>
      <td width="25" align=middle><img border="0" src="skins/images/help_small.gif"></td>
      <td >&nbsp;<a onClick="javascript:Help('archives')" href="#">Explaining archives and<br>
        &nbsp;Their usage</a></td>
    </tr>
  </table>

    <tr>
        <td width=654 colspan="2" height="11">
    <img height=20 border=0 src="skins/images/blank.gif" width=1>
    <br>    </tr>
    <tr>
        <td width=654 colspan=2 height=14>
    <b>Available archives</b>
    </tr>
    <tr>

        <td width=654 colspan=2 height=1>
  <table width=641 height=100% cellspacing=0 cellpadding=0>
    <tr>
      <td width=8 bgcolor=#F7F6F4>&nbsp;</td>
      <td width=160 bgcolor=#F7F6F4><u>archivation date</u></td>
      <td width=222 bgcolor=#F7F6F4><u>duration</u></td>
      <td width=81 bgcolor=#F7F6F4><u>news</u></td>
      <td width=110 bgcolor=#F7F6F4><u><!--action--></u></td>

    </tr>
HTML;

        if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archives "); }
                   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");
                $creation_date = date("d F Y",$file_arr[0]);
                $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];

                                $duration = (date("d M Y",$first_timestamp) ." - ". date("d M Y",$last_timestamp) );
                echo "
                                <tr>
                              <td ></td>
                              <td >$creation_date</td>
                              <td >$duration</td>
                              <td >$count</td>
                              <td ><a title='Edit the news in this archive' href=\"$PHP_SELF?mod=editnews&action=list&source=$id\">[edit]</a>  <a title='restore news from this archive to active news' href=\"$PHP_SELF?mod=tools&action=archive&subaction=unarchive&aid=$id\">[unarchive]</a>  <a title='Delete this archive' onClick=\"javascript:confirmdelete('$id', '$count');\" href=\"#\">[delete]</a></td>
                                </tr>
                ";
                           }
                   }
        closedir($handle);

    if($count == 0){
            echo"<tr><td align=center colspan=6><br>There are no archives</td></tr>";
    }

echo<<<HTML
</table>
</table>
HTML;

        echofooter();
}
// ********************************************************************************
// Make Archive
// ********************************************************************************
elseif($action == "doarchive")
{
    if(filesize("./data/news.txt") == 0){ msg("error", "Error !!!", "Sorry but there are no news to be archived", "$PHP_SELF?mod=tools&action=archive"); }
    if(filesize("./data/comments.txt") == 0){ msg("error", "Error !!!", "The comments file is empty and can not be archived", "$PHP_SELF?mod=tools&action=archive"); }

    $arch_name = time()+($config_date_adjust*60);
        if(!@copy("./data/news.txt","./data/archives/$arch_name.news.arch"))                  { msg("error","Error !!!","Can not create file ./data/archives/$arch_name.news.arch", "$PHP_SELF?mod=tools&action=archive");}
        if(!@copy("./data/comments.txt","./data/archives/$arch_name.comments.arch")) { msg("error","Error !!!","Can not create file ./data/archives/$arch_name.comments.arch", "$PHP_SELF?mod=tools&action=archive");}

    $handle = fopen("./data/news.txt","w");
        fclose($handle);
        $handle = fopen("./data/comments.txt","w");
        fclose($handle);

        msg("archives", "Archive Saved", "&nbsp&nbsp; All active news were successfully added to archives file with name  <b>$arch_name.news.arch</b>", "$PHP_SELF?mod=tools&action=archive");
}
// ********************************************************************************
// Do Delete Archive
// ********************************************************************************
elseif($action == "dodeletearchive"){
        $success = 0;
        if(!$handle = opendir("./data/archives")){ die("<center>Can not open directory $cutepath/data/archive "); }
                   while (false !== ($file = readdir($handle))){
                           if($file == "$archive.news.arch" or  $file == "$archive.comments.arch"){
                    unlink("./data/archives/$file"); $success ++;
                           }
                }
        closedir($handle);

    if($success == 2){
                msg("info", "Arhcive Deleted", "The archive was successfully deleted", "$PHP_SELF?mod=tools&action=archive");
    }elseif($success == 1){
            msg("error", "Error !!!", "Either the comments part or the news part of the archive was not deleted", "$PHP_SELF?mod=tools&action=archive");
    }else{
            msg("error", "Error !!!", "The archive you specified was not deleted, it is not on the server or you don't have permissions to delete it", "$PHP_SELF?mod=tools&action=archive");
    }

}
// ********************************************************************************
// Backup News and archives
// ********************************************************************************
elseif($action == "backup")
{
        echoheader("options", "Backup");
        echo'
     <script language="javascript">
    function confirmdelete(id){
        var agree=confirm("Do you really want to permanently delete this backup ?");
        if (agree)
        document.location="index.php?mod=tools&action=dodeletebackup&backup="+id;
        }
    function confirmrestore(id){
        var agree=confirm("Do you really want to restore your news from this backup ?\nAll current news and archives will be overwritten.");
        if (agree)
        document.location="index.php?mod=tools&action=dorestorebackup&backup="+id;
        }
    </script>
        <table border=0 cellpading=0 cellspacing=0 width="645" >
    <td width=321 height="33">
    <b>Create BackUp</b>
<table border=0 cellpading=0 cellspacing=0 class="panel" cellpadding="10" width="390" >
    <form method=post action="'.$PHP_SELF.'">
    <tr>
    <td height="25" width="366">
    Name of the BackUp: <input type=text name=back_name>&nbsp; <input type=submit value=" Proceed ">

    </td>
    </tr>
        <input type=hidden name=action value=dobackup>
        <input type=hidden name=mod value=tools>
</form>
</table>
    <tr>
        <td width=654 height="11">
    <img height=20 border=0 src="skins/images/blank.gif" width=1>
    <br>    </tr>
    <tr>
        <td width=654 height=14>
    <b>Available BackUps</b>
    </tr>
    <tr>
        <td width=654 height=1>
  <table width=641 height=100% cellspacing=0 cellpadding=0>
    <tr>
      <td width=2% bgcolor=#F7F6F4>&nbsp;</td>
      <td width=40% bgcolor=#F7F6F4><u>name</u></td>
      <td width=22% bgcolor=#F7F6F4><u>active news</u></td>
      <td width=16% bgcolor=#F7F6F4><u>archives</u></td>
      <td width=20% bgcolor=#F7F6F4><u>action</u></td>
    </tr>';

        $count = 0;
        if(!$handle = opendir("./data/backup")){ die("<center>Can not open directory $cutepath/data/backup "); }
                   while (false !== ($file = readdir($handle)))
           {
                           if($file != "." and $file != ".." and is_dir("./data/backup/$file"))
            {
                $archives_count = 0;
                                $archives_handle = @opendir("./data/backup/$file/archives");
                                           while (false !== ($arch = readdir($archives_handle))){
                                                   if(eregi(".news.arch", $arch)){ $archives_count++; }
                                           }
                                closedir($archives_handle);


                $news_count = count(file("./data/backup/$file/news.txt"));
                echo "<tr>
                                      <td></td>
                                      <td>$file</td>
                      <td>&nbsp;$news_count</td>
                      <td>&nbsp;$archives_count</td>
                                      <td><a onClick=\"javascript:confirmdelete('$file'); return(false)\" href=\"$PHP_SELF?mod=tools&action=dodeletebackup&backup=$file\">[delete]</a> <a onClick=\"javascript:confirmrestore('$file'); return(false)\" href=\"$PHP_SELF?mod=tools&action=dorestorebackup&backup=$file\">[restore]</a></td>
                                          </tr>";
                $count++;
            }
                   }
        closedir($handle);

    if($count == 0){
            echo"<tr><td colspan=5><p align=center><br>There are no backups</p></td></tr>";
    }

        echo'</table></table>';

    echofooter();
}

// ********************************************************************************
// Do Delete Backup
// ********************************************************************************
elseif($action == "dodeletebackup")
{

function listdir($dir){

        $current_dir = opendir($dir);
        while($entryname = readdir($current_dir)){
                if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
                        listdir("${dir}/${entryname}");
                }elseif($entryname != "." and $entryname!=".."){
            unlink("${dir}/${entryname}");
            }
    }
    @closedir($current_dir);
    rmdir(${dir});
}
listdir("./data/backup/$backup");

msg("info", "Backup Deleted", "The backup was successfully deleted.", "$PHP_SELF?mod=tools&action=backup");

}
// ********************************************************************************
// Do restore backup
// ********************************************************************************
elseif($action == "dorestorebackup"){


if(!@copy("./data/backup/$backup/news.txt", "./data/news.txt")){ msg("error", "error", "./data/backup/$backup/news.txt", "$PHP_SELF?mod=tools&action=backup"); }
if(!@copy("./data/backup/$backup/comments.txt", "./data/comments.txt")){ msg("error", "error", "./data/backup/$backup/comments.txt", "$PHP_SELF?mod=tools&action=backup"); }

$dirp = opendir("./data/backup/$backup/archives");
while($entryname = readdir($dirp)){
        if(!is_dir("./data/backup/$backup/archives/$entryname") and $entryname!="." and $entryname!=".."){
                if(!@copy("./data/backup/$backup/archives/$entryname", "./data/archives/$entryname")){ msg("error", "error", "Can not copy ./data/backup/$backup/archives/$entryname"); }
    }
}

msg("info", "Backup Restored", "The backup was successfully restored.", "$PHP_SELF?mod=tools&action=backup");
}
// ********************************************************************************
// Make The BackUp
// ********************************************************************************
elseif($action == "dobackup")
{
        $back_name = eregi_replace(" ", "-", $back_name);


    if(filesize("./data/news.txt") == 0){msg("error", "Error !!!", "The news file is empty and can not be backed-up", "$PHP_SELF?mod=tools&action=backup");}
    if(filesize("./data/comments.txt") == 0){msg("error", "Error !!!", "The comments file is empty and can not be backed-up", "$PHP_SELF?mod=tools&action=backup");}

        if(is_readable("./data/backup/$back_name")){ msg("error", "Error !!!", "A backup with this name already exist", "$PHP_SELF?mod=tools&action=backup"); }
        if(!is_readable("./data/backup")){ mkdir("./backup", 0777); }
    if(!is_writable("./data/backup")){ msg("error", "Error !!!", "The directory ./data/backup is not writable, please chmod it"); }
    mkdir("./data/backup/$back_name", 0777);
        mkdir("./data/backup/$back_name/archives", 0777);

        if(!@copy("./data/news.txt", "./data/backup/$back_name/news.txt")){ die("Can not copy news.txt file to ./data/backup/$back_name :("); }
        if(!@copy("./data/comments.txt","./data/backup/$back_name/comments.txt")){ die("Can not copy comments.txt file to ./data/backup/$back_name :("); }

        if(!$handle = opendir("./data/archives")){ die("Can not create file"); }
        while(false !== ($file = readdir($handle)))
    {
                if($file != "." and $file != "..")
        {
                        if(!@copy("./data/archives/$file", "./data/backup/$back_name/archives/$file")){ die("Can not copy archive file to ./data/backup/$back_name/archives/$file :("); }
                }
    }
        closedir($handle);

    msg("info", "Backup", "All news and archives were successfully BackedUp under directory  './data/backup/$back_name'", "$PHP_SELF?mod=tools&action=backup");
}

?>