Initial Commit
[contractdashboard.git] / cutenews / inc / editusers.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
<?PHP

if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission to edit users"); }
// ********************************************************************************
// List All Available Users + Show Add User Form
// ********************************************************************************
if($action == "list")
{
    echoheader("users","Manage Users");

        echo'<script language="javascript">
        <!-- begin
        function popupedit(id){
        window.open(\''.$PHP_SELF.'?mod=editusers&action=edituser&id=\'+id,\'User\',\'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=360,height=210\');
        }
        function confirmdelete(id){
        var agree=confirm("Are you sure you want to delete this user ?");
        if (agree)
        document.location="'.$PHP_SELF.'?mod=editusers&action=dodeleteuser&id="+id;
        }
        // end -->
        </script>
        <table border=0 cellpading=0 cellspacing=0 width=654>
    <tr>
        <td width=654 colspan="6">
<!-- Start add edit users table + info + help -->
  <table border="0" width="657"  cellspacing="0" cellpadding="0" height="81" >
    <tr>
      <td valign="bottom" width="311" valign="top" height="1">

      <b>Add User</b>

      </td>
      <td width="5" valign="top"  rowspan="3" height="81">

      </td>
      <td valign="bottom" width="330" height="1"><b>User Levels</b></td>
    </tr>

    <tr>
      <td width="311" rowspan="2" valign="top" height="60" >

<!-- Add User Table -->
  <table class="panel" cellspacing="0" cellpadding="0" width="100%">
  <form method=post action="'.$PHP_SELF.'">
    <tr>
      <td >&nbsp;Username</td>
      <td ><input size=21 type=text name=regusername></td>
    </tr>
    <tr>
      <td >&nbsp;Password</td>
      <td ><input size=21 type=text name=regpassword></td>
    </tr>
    <tr>
      <td >&nbsp;Nickname</td>
      <td ><input size=21 type=text name=regnickname></td>
    </tr>
    <tr>
      <td >&nbsp;Email</td>
      <td ><input size=21 type=text name=regemail></td>
    </tr>
    <tr>
      <td >&nbsp;Access Level</td>
      <td ><select name=reglevel>
           <option value=4>4 (commenter)</option>
           <option selected value=3>3 (journalist)</option>
           <option value=2>2 (editor)</option>
           <option value=1>1 (administrator)</option>
                         </select>
                </td>
    </tr>
    <tr>
      <td >&nbsp;</td>
      <td height="35"><input type=submit value="Add User">
          <input type=hidden name=action value=adduser>
                    <input type=hidden name=mod value=editusers>
      </td>
    </tr>
        </form>
  </table>
<!-- End Add User Table -->

      </td>
      <td width="330" height="1" valign="top" >

<!-- User Levels Table -->
  <table class="panel" cellspacing="3" cellpadding="0" width="100%">
    <tr>
      <td valign="top">&nbsp;Administrator : have full access and privilegies<br>
        &nbsp;Editor : can add news and edit others posts<br>
        &nbsp;Journalist : can only add news (must be approved)<br>
        &nbsp;Commenter : only post comments</td>
    </tr>
  </table>
<!-- End User Levels Table -->

      </td>
    </tr>
    <tr>
      <td width="330" valign="top" align=center height="70"><br>

      <!-- HELP -->
   <table height="25" cellspacing="0" cellpadding="0">
    <tr>
      <td width="25" align=middle><img border="0" src="skins/images/help_small.gif" width="25" height="25"></td>
      <td >&nbsp;<a onClick="javascript:Help(\'users\')" href="#">Understanding user levels</a>&nbsp;</td>
    </tr>
  </table>
     <!-- END HELP -->
      </td>
    </tr>
  </table>
<!-- END add edit users table + info + help -->

    </tr>
    <tr>
        <td width=654 colspan="6">
    </tr>
    <tr>
        <td width=650 colspan="6">
    <img height=20 border=0 src="skins/images/blank.gif" width=1><br>
    <b>Edit Users</b>
    </tr>

    <tr>
    <td width=130 bgcolor="#F7F6F4">
        &nbsp;<u>Username</u>
        <td width=197 bgcolor="#F7F6F4">
    <u>registration date</u>
        <td width=2 bgcolor="#F7F6F4">
    &nbsp;
        <td width=83 bgcolor="#F7F6F4">
    <u>written news</u>
        <td width=132 bgcolor="#F7F6F4">
    <u>Access Level</u>
        <td width=93 bgcolor="#F7F6F4">
    <u>action</u>
    </tr>';

    $all_users = file("./data/users.db.php");
    $i = 1;
    foreach($all_users as $user_line)
    {
        $i++; $bg = "";
        if($i%2 == 0){ $bg = "bgcolor=\"#f7f6f4\""; }
        if(!eregi("<\?",$user_line)){
        $user_arr = explode("|", $user_line);

        if(isset($user_arr[9]) and $user_arr[9] != ''){ $last_login = date('r',$user_arr[9]); }
        else{ $last_login = 'never'; }

        switch($user_arr[1]){
        case 1: $user_level = "administrator"; break;
        case 2: $user_level = "editor"; break;
        case 3: $user_level = "journalist"; break;
        case 4: $user_level = "commenter"; break;
        }
        echo"<tr $bg title='$user_arr[2]&#039;s last login was on: $last_login'>
                <td width=143>
            &nbsp;$user_arr[2]
                <td width=197>";
            echo( date("F, d Y @ H:i a",$user_arr[0]) );
                echo"<td width=2>
                <td width=83 >
            &nbsp;&nbsp;$user_arr[6]
                <td width=122>
            &nbsp;$user_level
                <td width=80 title=''>
            <a  onClick=\"javascript:popupedit('$user_arr[0]'); return(false)\" href=#>[edit]</a>&nbsp;<a onClick=\"javascript:confirmdelete('$user_arr[0]'); return(false)\"  href=\"$PHP_SELF?mod=editusers&action=dodeleteuser&id=$user_arr[0]\">[delete]</a>
            </tr>";
                }
    }

        echo"</table>";

    echofooter();
}
// ********************************************************************************
// Add User
// ********************************************************************************
elseif($action == "adduser")
{
        if(!$regusername){ msg("error","Error !!!", "Username can not be blank", "javascript:history.go(-1)"); }
        if(!$regpassword){ msg("error","Error !!!", "Password can not be blank", "javascript:history.go(-1)"); }

    $all_users = file("./data/users.db.php");
    foreach($all_users as $user_line)
    {
                $user_arr = explode("|", $user_line);
        if($user_arr[2] == $regusername){ msg("error", "Error !!!", "Sory but user with this username already exist", "javascript:history.go(-1)"); }
    }

        $add_time = time()+($config_date_adjust*60);
        $regpassword = md5($regpassword);

        $old_users_file = file("./data/users.db.php");
        $new_users_file = fopen("./data/users.db.php", "a");

        fwrite($new_users_file, "$add_time|$reglevel|$regusername|$regpassword|$regnickname|$regemail|0|0||||\n");

        fclose($new_users_file);

    switch($reglevel){
        case "1": $level = "administrator"; break;
        case "2": $level = "editor"; break;
        case "3": $level = "journalist"; break;
        case "4": $level = "commenter"; break;
        }
        msg("info","User Added","The user <b>$regusername</b> was successfully added as <b>$level</b>", "$PHP_SELF?mod=editusers&action=list");
}
// ********************************************************************************
// Edit User Details
// ********************************************************************************
elseif($action == "edituser")
{

        $users_file = file("./data/users.db.php");
    foreach($users_file as $user_line){
            $user_arr = explode("|", $user_line);
        if($id == $user_arr[0]){
                        break;
        }
    }

        if(isset($user_arr[9]) and $user_arr[9] != ''){ $last_login = date('r',$user_arr[9]); }
        else{ $last_login = 'never'; }

    echo"<html><head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">
    <title>Edit Users</title>
    <style type=\"text/css\">
    <!--
        select, option, textarea, input {
        BORDER-RIGHT: #808080 1px solid;
        BORDER-TOP: #808080 1px solid;
        BORDER-BOTTOM: #808080 1px solid;
        BORDER-LEFT: #808080 1px solid;
        COLOR: #000000;
        FONT-SIZE: 11px;
        FONT-FAMILY: Verdana; BACKGROUND-COLOR: #ffffff }
            TD {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt;}
            BODY {text-decoration: none; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 3pt;}
            .header { font-size : 16px; font-weight: bold; color: #808080; font-family: verdana; text-decoration: none; }
    -->
    </style>
    </head>
    <body>
    <form action=\"$PHP_SELF\" method=post><table width=\"828\" cellspacing=\"0\" cellpadding=\"0\" height=\"13\">
    <td width=\"826\" height=\"21\" colspan=\"2\"><div class=header>$user_arr[2] <font size=\"2\">($user_arr[4])</font></div>

    <tr>
    <td width=\"126\" height=\"20\" bgcolor=\"#f7f6f4\">written news
    <td  height=\"20\" bgcolor=\"#f7f6f4\" width=\"698\">
    $user_arr[6]
    </tr>

    <tr>
    <td width=\"126\" height=\"20\" bgcolor=\"#f7f6f4\">last login date
    <td  height=\"20\" bgcolor=\"#f7f6f4\" width=\"698\">
    $last_login
    </tr>

    <tr>
    <td width=\"126\" height=\"20\">
    registration date
    <td  height=\"20\" width=\"698\">";
        echo date("r", $user_arr[0]);
    echo"
    </tr>

    <tr>
    <td width=\"126\" height=\"20\" bgcolor=\"#f7f6f4\">
    Email
    <td  height=\"20\" bgcolor=\"#f7f6f4\" width=\"698\">
    $user_arr[5]
    </tr>

    <tr>
         <td width=\"126\" height=\"20\">
    New Password
    <td  height=\"20\" width=\"698\">
    <input size=\"20\" name=\"editpassword\" >
    </tr>

    <tr>
    <td width=\"126\" height=\"20\" bgcolor=\"#f7f6f4\">
    Access Level
    <td  height=\"20\" bgcolor=\"#f7f6f4\" width=\"698\">
    <select name=editlevel>";

        if($user_arr[1] == 4){echo" <option value=4 selected>4 (commenter)</option>";}    else {echo" <option value=4>4 (commenter)</option>";}
        if($user_arr[1] == 3){echo" <option value=3 selected>3 (journalist)</option>";}   else {echo" <option value=3>3 (journalist)</option>";}
        if($user_arr[1] == 2){echo" <option value=2 selected>2 (editor)</option>";}       else {echo" <option value=2>2 (editor)</option>";}
        if($user_arr[1] == 1){echo" <option value=1 selected>1 (administrator)</option>";}else {echo" <option value=1>1 (administrator)</option>";}

    echo"</select>
    </tr>
    <tr>
    <td width=\"826\" height=\"7\" colspan=\"2\">
    <br />
    <input type=submit value=\"Save Changes\">   <input type=button value=\"Cancel\" onClick=\"window.close();\">
    <input type=hidden name=id value=$id>
    <input type=hidden name=mod value=editusers>
    <input type=hidden name=action value=doedituser>
    </tr>
    </table></form>
    </body>
    </html>";


}
// ********************************************************************************
// Do Edit User
// ********************************************************************************
elseif($action == "doedituser")
{
        if(!$id){ die("This is not a valid user."); }

    $old_db = file("./data/users.db.php");
    $new_db = fopen("./data/users.db.php", "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{
                if($editpassword != ""){
                        $old_db_arr[3] = md5($editpassword);
                    if($old_db_arr[2] == $username){setcookie("md5_password", $old_db_arr[3]); }
            }
                fwrite($new_db,"$old_db_arr[0]|$editlevel|$old_db_arr[2]|$old_db_arr[3]|$old_db_arr[4]|$old_db_arr[5]|$old_db_arr[6]|$old_db_arr[7]|$old_db_arr[8]|$old_db_arr[9]||\n");
        }
    }
    fclose($new_db);
        $result = "Changes Saved";

        echo"<html>
    <head>
    <title>Edit Users</title>
    </head>
    <body bgcolor=#FFFFFF>
    <table border=0 cellpading=0 cellspacing=0 width=100% height=100% >
    <tr><td align=middle width=154>
    <p align=right><img border=0 src=\"skins/images/info.gif\" width=60 height=57>
    </td><td align=middle width=558>
    <p align=left>$result
    </td></tr>
    </table>
    </body>
    </html>";

}
// ********************************************************************************
// Delete User
// ********************************************************************************
elseif($action == "dodeleteuser")
{
        if(!$id){ die("This is not a valid user."); }

        $old_users_file = file("./data/users.db.php");
        $new_users_file = fopen("./data/users.db.php", "w");
    foreach($old_users_file as $old_user_line){
            $old_user_line_arr = explode("|", $old_user_line);
        if($id != $old_user_line_arr[0]){
                        fwrite($new_users_file, $old_user_line);
        }else{
                        $deleted = TRUE; $user = $old_user_line_arr[2];
        }
    }
        fclose($new_users_file);

    msg("info","User Deleted","The user $user was successfully deleted.", "$PHP_SELF?mod=editusers&action=list");
}
?>