~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to html/inc/prefs.inc

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
// This file is part of BOINC.
3
3
// http://boinc.berkeley.edu
4
 
// Copyright (C) 2008 University of California
 
4
// Copyright (C) 2010 University of California
5
5
//
6
6
// BOINC is free software; you can redistribute it and/or modify it
7
7
// under the terms of the GNU Lesser General Public License
42
42
// <project_preferences>
43
43
//    <resource_share>4</resource_share>
44
44
//    [ <allow_beta_work>0|1</allow_beta_work> ]
 
45
//    [ <no_cpu>1</no_cpu> ]
 
46
//    [ <no_cuda>1</no_cuda> ]
 
47
//    [ <no_ati>1</no_ati> ]
45
48
//    <project-specific>
46
49
//            ... (arbitrary project-specific XML)
47
50
//    </project-specific>
56
59
// Various functions are defined below for converting between these forms,
57
60
// and also to/from HTML form elements
58
61
 
 
62
error_reporting(E_ALL);
 
63
ini_set('display_errors', true);
 
64
ini_set('display_startup_errors', true);
 
65
 
 
66
include_once("../inc/prefs_util.inc");
59
67
include_once("../project/project_specific_prefs.inc");
60
68
 
61
 
// strings describing various preference fields
62
 
//
63
 
define("CPU_LIMIT_DESC", "Processor usage");
64
 
define("SUSPEND_WHILE_ON_BATTERIES_DESC",
65
 
    "Suspend work while computer is on battery power?
66
 
    <br><span class=note>(matters only for portable computers)</span>"
67
 
);
68
 
define("RUN_IF_USER_ACTIVE_DESC",
69
 
    "Suspend work while computer is in use?"
70
 
);
71
 
define("IDLE_TIME_TO_RUN_DESC", "'In use' means mouse/keyboard activity in last");
72
 
define("SUSPEND_IF_NO_RECENT_INPUT_DESC",
73
 
    "Suspend work if no mouse/keyboard activity in last
74
 
    <br><span class=note>(Needed to enter low-power mode on some computers)
75
 
    <br>Enforced by version 5.10.14+</span>"
76
 
);
77
 
define("START_END_DESC", "Do work only between the hours of");
78
 
define("START_END_DESC2", "<br><span class=note>(no restriction if equal)</span>");
79
 
define("LEAVE_APPS_IN_MEMORY_DESC",
80
 
    "Leave applications in memory while suspended?
81
 
    <br><span class=note>(suspended applications will consume swap space if 'yes')</span>");
82
 
define("CPU_SCHEDULING_DESC", "Switch between applications every
83
 
    <br><span class=note>(recommended: 60 minutes)</span>");
84
 
define("CONFIRM_BEFORE_CONNECTING_DESC",
85
 
    "Confirm before connecting to Internet?
86
 
    <br><span class=note>(matters only if you have a modem, ISDN or VPN connection)</span>"
87
 
);
88
 
define("HANGUP_IF_DIALED_DESC",
89
 
    "Disconnect when done?
90
 
    <br><span class=note>(matters only if you have a modem, ISDN or VPN connection)</span>"
91
 
);
92
 
define("WORK_BUF_MIN_DAYS_DESC",
93
 
    "Computer is connected to the Internet about every
94
 
    <br><span class=note>(Leave blank or 0 if always connected.
95
 
    <br>BOINC will try to maintain at least this much work.)</span>
96
 
    "
97
 
);
98
 
define("WORK_BUF_ADDITIONAL_DAYS_DESC",
99
 
    "Maintain enough work for an additional
100
 
    <br><span class=note>Enforced by version 5.10+</span>
101
 
    "
102
 
);
103
 
define("MAX_NCPUS_PCT_DESC", "On multiprocessors, use at most<span class=note><br>Enforced by version 6.1+</span>");
104
 
define("MAX_NCPUS_PCT_DESC2", "% of the processors");
105
 
define("MAX_CPUS_DESC", "On multiprocessors, use at most<span class=note><br>Enforced by version 5.10 and earlier</span>");
106
 
define("MAX_CPUS_DESC2", "processors");
107
 
define("USE_AT_MOST", "Use at most");
108
 
define("USE_AT_MOST2", "Use at most<span class=note><br>(Can be used to reduce CPU heat)<br>Enforced by version 5.6+</span>");
109
 
define("USE_AT_MOST3", "Use at most<br><span class=note>Enforced by version 5.8+</span>");
110
 
define("CPU_USAGE_LIMIT_DESC2", "percent of CPU time");
111
 
define("DISK_INTERVAL_DESC", "Write to disk at most every");
112
 
define("DISK_LIMIT_DESC", "Disk and memory usage");
113
 
define("DISK_MIN_FREE_GB_DESC", "Leave at least");
114
 
define("DISK_SCHED_MIN_FREE_DESC1", "<br><span class=note>(Values smaller than ");
115
 
define("DISK_SCHED_MIN_FREE_DESC2", " are ignored)</span>");
116
 
define("DISK_MAX_USED_PCT_DESC2", "% of total disk space");
117
 
define("VM_MAX_USED_PCT_DESC2", "% of page file (swap space)");
118
 
define("RAM_MAX_USED_BUSY_PCT_DESC2", "% of memory when computer is in use");
119
 
define("RAM_MAX_USED_IDLE_PCT_DESC2", "% of memory when computer is not in use");
120
 
define("NETWORK_LIMIT_DESC", "Network usage");
121
 
define("MAX_BYTES_SEC_DOWN_DESC", "Maximum download rate:");
122
 
define("MAX_BYTES_SEC_UP_DESC", "Maximum upload rate:");
123
 
define("NET_START_END_DESC",
124
 
    "Use network only between the hours of
125
 
    <br><span class=note>Enforced by version 4.46+</span>"
126
 
);
127
 
define("DONT_VERIFY_IMAGES_DESC",
128
 
    "Skip image file verification?
129
 
    <br><span class=note>Check this ONLY if your Internet provider
130
 
    modifies image files (UMTS does this, for example).
131
 
    <br>Skipping verification reduces the security of BOINC.</span>"
132
 
);
133
 
 
134
 
define("BYTE_CONVERSION", 1000.0);
135
 
define("BYTE_UNITS", "Kbytes/sec");
136
 
define("BYTE_ABBR", "KB/s");
137
 
define("ALLOW_BETA_WORK",
138
 
    "Run test applications?<br>
139
 
    <span class=note>This helps us develop applications,
140
 
    but may cause jobs to fail on your computer</span>"
141
 
);
 
69
$app_types = get_app_types();
 
70
 
 
71
$venues = array("home", "school", "work");
 
72
 
 
73
$cpu_prefs = array(
 
74
    new PREF_BOOL(
 
75
        tra(
 
76
            "Suspend work while computer is on battery power? %1 Matters only for portable computers %2",
 
77
            "<br><span class=note>",
 
78
            "</span>"
 
79
        ),
 
80
        "run_on_batteries",
 
81
        false, true
 
82
    ),
 
83
    new PREF_BOOL(
 
84
        tra("Suspend work while computer is in use?"),
 
85
        "run_if_user_active",
 
86
        true, true
 
87
    ),
 
88
    new PREF_BOOL(
 
89
        tra(
 
90
            "Suspend GPU work while computer is in use? %1 Enforced by version 6.6.21+ %2",
 
91
            "<br><span class=note>",
 
92
            "</span>"
 
93
        ),
 
94
        "run_gpu_if_user_active",
 
95
        false, true
 
96
    ),
 
97
    new PREF_NUM(
 
98
        tra("'In use' means mouse/keyboard activity in last"),
 
99
        "idle_time_to_run",
 
100
        new NUM_SPEC(tra("minutes"), 1, 9999, 3)
 
101
    ),
 
102
    new PREF_NUM(
 
103
        tra(
 
104
            "Suspend work if no mouse/keyboard activity in last %1 Needed to enter low-power mode on some computers %2",
 
105
            "<br><span class=note>",
 
106
            "</span>"
 
107
        ),
 
108
        "suspend_if_no_recent_input",
 
109
        new NUM_SPEC(tra("minutes"), 0, 9999, 0)
 
110
    ),
 
111
    new PREF_NUM(
 
112
        tra(
 
113
            "Suspend work if CPU usage is above %1 0 means no restriction<br>Enforced by version 6.10.30+ %2",
 
114
            "<br><span class=note>",
 
115
            "</span>"
 
116
        ),
 
117
        "suspend_cpu_usage",
 
118
        new NUM_SPEC("%", 0, 100, 25)
 
119
    ),
 
120
    new PREF_HOUR_RANGE(
 
121
        tra("Do work only between the hours of %1 No restriction if equal %2",
 
122
            "<br><span class=note>",
 
123
            "</span>"
 
124
        ),
 
125
        "start_hour", "end_hour"
 
126
    ),
 
127
    new PREF_BOOL(
 
128
        tra(
 
129
            "Leave tasks in memory while suspended? %1 Suspended tasks will consume swap space if 'yes' %2",
 
130
            "<br><span class=note>",
 
131
            "</span>"
 
132
        ),
 
133
        "leave_apps_in_memory",
 
134
        false
 
135
    ),
 
136
    new PREF_NUM(
 
137
        tra(
 
138
            "Switch between tasks every %1 Recommended: 60 minutes %2",
 
139
            "<br><span class=note>",
 
140
            "</span>"
 
141
        ),
 
142
        "cpu_scheduling_period_minutes",
 
143
        new NUM_SPEC(tra("minutes"), 1, 9999, 60)
 
144
    ),
 
145
    new PREF_NUM(
 
146
        tra("On multiprocessors, use at most"),
 
147
        "max_cpus",
 
148
        new NUM_SPEC(tra("processors"), 0, 9999, 0)
 
149
    ),
 
150
    new PREF_NUM(
 
151
        tra(
 
152
            "On multiprocessors, use at most %1 Enforced by version 6.1+ %2",
 
153
            "<br><span class=note>",
 
154
            "</span>"
 
155
        ),
 
156
        "max_ncpus_pct",
 
157
        new NUM_SPEC(tra("% of the processors"), 0, 100, 100)
 
158
    ),
 
159
    new PREF_NUM(
 
160
        tra(
 
161
            "Use at most %1 Can be used to reduce CPU heat %2",
 
162
            "<br><span class=note>",
 
163
            "</span>"
 
164
        ),
 
165
        "cpu_usage_limit",
 
166
        new NUM_SPEC(tra("% of CPU time"), 0, 100, 100)
 
167
    ),
 
168
);
 
169
 
 
170
$dp = get_disk_space_config();
 
171
 
 
172
$disk_prefs = array(
 
173
    new PREF_NUM(
 
174
        tra("Disk: use at most"),
 
175
        "disk_max_used_gb",
 
176
        new NUM_SPEC(tra("GB"), 0, 9999999, $dp->disk_max_used_gb)
 
177
    ),
 
178
    new PREF_NUM(
 
179
        tra("Disk: leave free at least %1 Values smaller than %2 are ignored %3",
 
180
            "<br><span class=note>",
 
181
            "0.001",
 
182
            "</span>"
 
183
        ),
 
184
        "disk_min_free_gb",
 
185
        new NUM_SPEC(tra("GB"), 0.001, 9999999, $dp->disk_min_free_gb)
 
186
    ),
 
187
    new PREF_NUM(
 
188
        tra("Disk: use at most"),
 
189
        "disk_max_used_pct",
 
190
        new NUM_SPEC(tra("% of total"), 0, 100, $dp->disk_max_used_pct)
 
191
    ),
 
192
    new PREF_NUM(
 
193
        tra("Tasks checkpoint to disk at most every"),
 
194
        "disk_interval",
 
195
        new NUM_SPEC(tra("seconds"), 0, 9999999, 60)
 
196
    ),
 
197
    new PREF_NUM(
 
198
        tra("Swap space: use at most"),
 
199
        "vm_max_used_pct",
 
200
        new NUM_SPEC(tra("% of total"), 0, 100, 75)
 
201
    ),
 
202
    new PREF_NUM(
 
203
        tra("Memory: when computer is in use, use at most"),
 
204
        "ram_max_used_busy_pct",
 
205
        new NUM_SPEC(tra("% of total"), 0, 100, 50)
 
206
    ),
 
207
    new PREF_NUM(
 
208
        tra("Memory: when computer is not in use, use at most"),
 
209
        "ram_max_used_idle_pct",
 
210
        new NUM_SPEC(tra("% of total"), 0, 100, 90)
 
211
    ),
 
212
);
 
213
 
 
214
$net_prefs = array(
 
215
    new PREF_NUM(
 
216
        tra(
 
217
            "Computer is connected to the Internet about every %1 Leave blank or 0 if always connected. %2 BOINC will try to maintain at least this much work. %3",
 
218
            "<br><span class=note>",
 
219
            "<br>",
 
220
            "</span>"
 
221
        ),
 
222
        "work_buf_min_days",
 
223
        new NUM_SPEC(tra("days"), 0, 10, 0)
 
224
    ),
 
225
    new PREF_NUM(
 
226
        tra("Maintain enough work for an additional"),
 
227
        "work_buf_additional_days",
 
228
        new NUM_SPEC(tra("days"), 0, 10, .25)
 
229
    ),
 
230
    new PREF_BOOL(
 
231
        tra(
 
232
            "Confirm before connecting to Internet? %1 Matters only if you have a modem, ISDN or VPN connection %2",
 
233
            "<br><span class=note>",
 
234
            "</span>"
 
235
        ),
 
236
        "confirm_before_connecting",
 
237
        false
 
238
    ),
 
239
    new PREF_BOOL(
 
240
        tra(
 
241
            "Disconnect when done? %1 Matters only if you have a modem, ISDN or VPN connection %2",
 
242
            "<br><span class=note>",
 
243
            "</span>"
 
244
        ),
 
245
        "hangup_if_dialed",
 
246
        false
 
247
    ),
 
248
    new PREF_NUM(
 
249
        tra("Maximum download rate:"),
 
250
        "max_bytes_sec_down",
 
251
        new NUM_SPEC(tra("Kbytes/sec"), 0, 9999999, 0, 1000)
 
252
    ),
 
253
    new PREF_NUM(
 
254
        tra("Maximum upload rate:"),
 
255
        "max_bytes_sec_up",
 
256
        new NUM_SPEC(tra("Kbytes/sec"), 0, 9999999, 0, 1000)
 
257
    ),
 
258
    new PREF_HOUR_RANGE(
 
259
        tra("Use network only between the hours of"),
 
260
        "net_start_hour", "net_end_hour"
 
261
    ),
 
262
    new PREF_NUM2(
 
263
        tra("Transfer at most %1 Enforced by version 6.10.46+ %2",
 
264
            "<br><span class=note>",
 
265
            "</span>"
 
266
        ),
 
267
        "daily_xfer_limit_mb",
 
268
        "daily_xfer_period_days",
 
269
        new NUM_SPEC(tra("Mbytes every"), 0, 9999999, 0),
 
270
        new NUM_SPEC(tra("days"), 0, 9999999, 0)
 
271
    ),
 
272
    new PREF_BOOL(
 
273
        tra(
 
274
            "Skip image file verification? %1 Check this ONLY if your Internet provider modifies image files (UMTS does this, for example). %2 Skipping verification reduces the security of BOINC. %3",
 
275
            "<br><span class=note>",
 
276
            "",
 
277
            "</span>"
 
278
        ),
 
279
        "dont_verify_images",
 
280
        false
 
281
    ),
 
282
);
 
283
 
 
284
$project_pref_descs = array(
 
285
    new PREF_NUM(
 
286
        $x = tra(
 
287
            "Resource share %1 Determines the proportion of your computer's resources allocated to this project. Example: if you participate in two BOINC projects with resource shares of 100 and 200, the first will get 1/3 of your resources and the second will get 2/3. %2",
 
288
            "<br><span class=note>",
 
289
            "</span>"
 
290
        ),
 
291
        "resource_share",
 
292
        new NUM_SPEC("", 0, 9999999, 100)
 
293
    ),
 
294
);
 
295
 
 
296
if ($app_types->count > 1) {
 
297
    if ($app_types->cpu) {
 
298
        $project_pref_descs[] = new PREF_BOOL (
 
299
            tra(
 
300
                "Use CPU %1 Enforced by version 6.10+ %2",
 
301
                "<br><span class=note>",
 
302
                "</span>"
 
303
            ),
 
304
            "no_cpu",
 
305
            false,
 
306
            true
 
307
        );
 
308
    }
 
309
    if ($app_types->ati) {
 
310
        $project_pref_descs[] = new PREF_BOOL (
 
311
            tra(
 
312
                "Use ATI GPU %1 Enforced by version 6.10+ %2",
 
313
                "<br><span class=note>",
 
314
                "</span>"
 
315
            ),
 
316
            "no_ati",
 
317
            false,
 
318
            true
 
319
        );
 
320
    }
 
321
    if ($app_types->cuda) {
 
322
        $project_pref_descs[] = new PREF_BOOL (
 
323
            tra(
 
324
                "Use NVIDIA GPU %1 Enforced by version 6.10+ %2",
 
325
                "<br><span class=note>",
 
326
                "</span>"
 
327
            ),
 
328
            "no_cuda",
 
329
            false,
 
330
            true
 
331
        );
 
332
    }
 
333
}
 
334
 
 
335
if (isset($project_has_beta) && $project_has_beta) {
 
336
    $project_pref_descs[] = new PREF_BOOL(
 
337
        tra(
 
338
            "Run test applications? %1 This helps us develop applications, but may cause jobs to fail on your computer %2",
 
339
            "<br><span class=note>",
 
340
            "</span>"
 
341
        ),
 
342
        "allow_beta_work",
 
343
        false
 
344
    );
 
345
}
 
346
if (defined("EMAIL_FROM")) {
 
347
    $x = "<br><span class=note>".tra("Emails will be sent from %1; make sure your spam filter accepts this address.", EMAIL_FROM)."</span>";
 
348
} else {
 
349
    $x = "";
 
350
}
 
351
 
 
352
$privacy_pref_descs = array (
 
353
    new PREF_BOOL(
 
354
        tra("Is it OK for %1 and your team (if any) to email you?", PROJECT).$x,
 
355
        "send_email",
 
356
        true,
 
357
        false
 
358
    ),
 
359
    new PREF_BOOL(
 
360
        tra("Should %1 show your computers on its web site?", PROJECT),
 
361
        "show_hosts",
 
362
        true,
 
363
        false
 
364
    ),
 
365
);
 
366
 
 
367
define("DISK_LIMIT_DESC", tra("Disk and memory usage"));
 
368
define("CPU_LIMIT_DESC", tra("Processor usage"));
 
369
define("NETWORK_LIMIT_DESC", tra("Network usage"));
142
370
 
143
371
// These texts are used in multiple places in prefs_edit.php and add_venue.php
144
 
define("PREFS_FORM_DESC1", "These preferences apply to all the BOINC projects in which you participate.<br><br>");
145
 
define("PREFS_FORM_ERROR_DESC", "<b>Unable to update preferences.</b> The values marked in red below were out of range or not numeric.<br><br>");
 
372
define("PREFS_FORM_DESC1", tra("These preferences apply to all the BOINC projects in which you participate.")."<br><br>");
 
373
define("PREFS_FORM_ERROR_DESC",
 
374
    tra(
 
375
        "%1Unable to update preferences.%2 The values marked in red below were out of range or not numeric.",
 
376
        "<strong>",
 
377
        "</strong>"
 
378
    ).
 
379
    "<br><br>"
 
380
);
146
381
 
147
382
global $text;
148
383
global $parse_result;
149
384
global $top_parse_result;
150
385
global $in_project_specific;
151
386
global $venue_name;
152
 
global $disk_prefs;
153
 
 
154
387
 
155
388
// get default settings for disk space usage so the default user
156
389
// preferences match the settings used by the scheduler.
161
394
// if running the old scheduler, set <scheduler_disk_space_check_hardcoded>
162
395
// in config.xml so the right default is set for minimum free disk space
163
396
// 
164
 
$disk_prefs = null;
165
397
function get_disk_space_config() {
166
 
    global  $disk_prefs;
167
398
    global  $config;
168
 
    if ($disk_prefs == null) {
169
 
        $config = get_config();
170
 
        $disk_prefs->disk_max_used_gb = parse_config($config, "<default_disk_max_used_gb>");
171
 
        $disk_prefs->disk_max_used_pct = parse_config($config, "<default_disk_max_used_pct>");
172
 
        $disk_prefs->disk_min_free_gb = parse_config($config, "<default_disk_min_free_gb>");
173
 
        // set some defaults if not found
174
 
        if (!$disk_prefs->disk_max_used_gb) $disk_prefs->disk_max_used_gb = 100;  // 100 gb
175
 
        if (!$disk_prefs->disk_max_used_pct) $disk_prefs->disk_max_used_pct = 50; // 50 percent
176
 
        if (!$disk_prefs->disk_min_free_gb) $disk_prefs->disk_min_free_gb=.001;   // 1 megabyte
177
 
        // set mininimum free space scheduler allows 
178
 
        // - depends on which scheduler is running
179
 
        $disk_prefs->new_sched_flag = 1;
180
 
        $disk_prefs->sched_disk_min_free_gb = $disk_prefs->disk_min_free_gb;
181
 
        if (parse_config($config, "scheduler_disk_space_check_hardcoded>")) {
182
 
            $disk_prefs->new_sched_flag = 0;
183
 
            $disk_prefs->sched_disk_min_free_gb = 0;
184
 
        }    
185
 
    }
 
399
    $config = get_config();
 
400
    $dp->disk_max_used_gb = parse_config($config, "<default_disk_max_used_gb>");
 
401
    $dp->disk_max_used_pct = parse_config($config, "<default_disk_max_used_pct>");
 
402
    $dp->disk_min_free_gb = parse_config($config, "<default_disk_min_free_gb>");
 
403
    // set some defaults if not found
 
404
    if (!$dp->disk_max_used_gb) $dp->disk_max_used_gb = 100;  // 100 gb
 
405
    if (!$dp->disk_max_used_pct) $dp->disk_max_used_pct = 50; // 50 percent
 
406
    if (!$dp->disk_min_free_gb) $dp->disk_min_free_gb=.001;   // 1 megabyte
 
407
    // set mininimum free space scheduler allows 
 
408
    // - depends on which scheduler is running
 
409
    $dp->new_sched_flag = 1;
 
410
    $dp->sched_disk_min_free_gb = $dp->disk_min_free_gb;
 
411
    if (parse_config($config, "scheduler_disk_space_check_hardcoded>")) {
 
412
        $dp->new_sched_flag = 0;
 
413
        $dp->sched_disk_min_free_gb = 0;
 
414
    }    
186
415
       
187
 
    return $disk_prefs;
 
416
    return $dp;
188
417
}
189
418
 
190
419
 
192
421
    if ($x == "home") return;
193
422
    if ($x == "work") return;
194
423
    if ($x == "school") return;
195
 
    error_page("bad venue: $x");
 
424
    error_page(tra("bad venue: %1", $x));
196
425
}
197
426
 
198
427
function check_subset($x) {
199
428
    if ($x == "global") return;
200
429
    if ($x == "project") return;
201
 
    error_page("bad subset: $x");
202
 
}
203
 
 
204
 
// functions to convert between max_bytes_sec_* as stored in the
205
 
// database and max_bytes_sec_* as displayed/entered on the web
206
 
// pages. Currently max_bytes_sec_* is stored in bytes and
207
 
// displayed/entered in Kbytes.
208
 
//
209
 
function max_bytes_display_mode($db_bytes) {
210
 
    $disp_bytes = 0;
211
 
    if ($db_bytes) {
212
 
        $disp_bytes = $db_bytes / BYTE_CONVERSION;
213
 
    }
214
 
    return $disp_bytes;
215
 
}
216
 
 
217
 
function max_bytes_db_mode($disp_bytes) {
218
 
    $db_bytes = 0;
219
 
    if ($disp_bytes) {
220
 
        $db_bytes = $disp_bytes * BYTE_CONVERSION;
221
 
    }
222
 
    return $db_bytes;
 
430
    error_page(tra("bad subset: %1", $x));
223
431
}
224
432
 
225
433
// functions to parse preferences XML into a struct
260
468
    case "venue":
261
469
        $venue_name = $attrs["name"];
262
470
        $top_parse_result = $parse_result;
263
 
        $parse_result = initialize_prefs_before_parsing_global();
264
 
        //echo "VENUE PREFS AFTER INIT: <pre>";
265
 
        //var_dump($parse_result);
266
 
        //echo "</pre>";
 
471
        $parse_result = default_prefs_global();
267
472
        break;
268
473
    }
269
474
    $text = "";
275
480
    global $in_project_specific;
276
481
    global $top_parse_result;
277
482
    global $venue_name;
 
483
    global $project_pref_descs;
278
484
 
 
485
    foreach($project_pref_descs as $p) {
 
486
        if ($p->xml_parse($parse_result, $name, $text)) {
 
487
            return;
 
488
        }
 
489
    }
279
490
    switch($name) {
280
491
    case "venue":
281
 
        //echo "VENUE PREFS AFTER PARSE: <pre>";
282
 
        //var_dump($parse_result);
283
 
        //echo "</pre>";
284
492
        $top_parse_result->$venue_name = $parse_result;
285
493
        $parse_result = $top_parse_result;
286
494
        break;
288
496
        $parse_result->project_specific = $text;
289
497
        $in_project_specific = false;
290
498
        break;
291
 
    case "resource_share":
292
 
        $parse_result->resource_share = $text;
293
 
        break;
294
 
    case "allow_beta_work":
295
 
        $parse_result->allow_beta_work = $text;
296
 
        $parse_result->allow_beta_work_text = $parse_result->allow_beta_work?"yes":"no";
297
 
        break;
298
499
    case "project_preferences":
299
500
        break;
300
501
    default:
306
507
    }
307
508
}
308
509
 
309
 
function get_bool() {
310
 
    global $text;
311
 
    return (trim($text) != '0');
312
 
}
313
 
 
314
510
function element_end_global($parser, $name) {
315
511
    global $text;
316
512
    global $parse_result;
317
513
    global $top_parse_result;
318
514
    global $venue_name;
 
515
    global $cpu_prefs;
 
516
    global $disk_prefs;
 
517
    global $disk_prefs;
 
518
    global $net_prefs;
319
519
 
 
520
    foreach ($cpu_prefs as $p) {
 
521
        if ($p->xml_parse($parse_result, $name, $text)) {
 
522
            return;
 
523
        }
 
524
    }
 
525
    foreach ($disk_prefs as $p) {
 
526
        if ($p->xml_parse($parse_result, $name, $text)) {
 
527
            return;
 
528
        }
 
529
    }
 
530
    foreach ($net_prefs as $p) {
 
531
        if ($p->xml_parse($parse_result, $name, $text)) {
 
532
            return;
 
533
        }
 
534
    }
320
535
    switch($name) {
321
536
    case "venue":
322
537
        $top_parse_result->$venue_name = $parse_result;
323
538
        $parse_result = $top_parse_result;
324
539
        break;
325
 
    case "run_on_batteries":
326
 
        // deprecated, but parse anyway
327
 
        $parse_result->suspend_while_on_batteries = !get_bool();
328
 
        break;
329
 
    case "suspend_while_on_batteries":
330
 
        $parse_result->suspend_while_on_batteries = get_bool();
331
 
        break;
332
 
    case "run_if_user_active":
333
 
        $parse_result->suspend_if_user_active = false;
334
 
        break;
335
 
    case "idle_time_to_run":
336
 
        $parse_result->idle_time_to_run = $text;
337
 
        break;
338
 
    case "suspend_if_no_recent_input":
339
 
        $parse_result->suspend_if_no_recent_input = $text;
340
 
        break;
341
 
    case "start_hour":
342
 
        $parse_result->start_hour = $text;
343
 
        break;
344
 
    case "end_hour":
345
 
        $parse_result->end_hour = $text;
346
 
        break;
347
 
    case "leave_apps_in_memory":
348
 
        $parse_result->leave_apps_in_memory = true;
349
 
        break;
350
 
    case "cpu_scheduling_period_minutes":
351
 
        $parse_result->cpu_scheduling_period_minutes = $text;
352
 
        break;
353
 
    case "confirm_before_connecting":
354
 
        $parse_result->confirm_before_connecting = true;
355
 
        break;
356
 
    case "hangup_if_dialed":
357
 
        $parse_result->hangup_if_dialed = true;
358
 
        break;
359
 
    case "work_buf_min_days":
360
 
        $parse_result->work_buf_min_days = $text;
361
 
        break;
362
 
    case "work_buf_additional_days":
363
 
        $parse_result->work_buf_additional_days = $text;
364
 
        break;
365
 
    case "max_cpus":
366
 
        $parse_result->max_cpus = $text;
367
 
        break;
368
 
    case "max_ncpus_pct":
369
 
        $parse_result->max_ncpus_pct = $text;
370
 
        break;
371
 
    case "cpu_usage_limit":
372
 
        if (!$text) $text=100;
373
 
        $parse_result->cpu_usage_limit = $text;
374
 
        break;
375
 
    case "disk_interval":
376
 
        $parse_result->disk_interval = $text;
377
 
        break;
378
 
    case "disk_max_used_gb":
379
 
        $parse_result->disk_max_used_gb = $text;
380
 
        break;
381
 
    case "disk_max_used_pct":
382
 
        $parse_result->disk_max_used_pct = $text;
383
 
        break;
384
 
    case "disk_min_free_gb":
385
 
        $parse_result->disk_min_free_gb = $text;
386
 
        break;
387
 
    case "vm_max_used_pct":
388
 
        $parse_result->vm_max_used_pct = $text;
389
 
        break;
390
 
    case "ram_max_used_busy_pct":
391
 
        $parse_result->ram_max_used_busy_pct = $text;
392
 
        break;
393
 
    case "ram_max_used_idle_pct":
394
 
        $parse_result->ram_max_used_idle_pct = $text;
395
 
        break;
396
 
    case "max_bytes_sec_down":
397
 
        $parse_result->max_bytes_sec_down = $text;
398
 
        break;
399
 
    case "max_bytes_sec_up":
400
 
        $parse_result->max_bytes_sec_up = $text;
401
 
        break;
402
 
    case "net_start_hour":
403
 
        $parse_result->net_start_hour = $text;
404
 
        break;
405
 
    case "net_end_hour":
406
 
        $parse_result->net_end_hour = $text;
407
 
        break;
408
 
    case "dont_verify_images":
409
 
        $parse_result->dont_verify_images = true;
410
 
        break;
411
540
    case "mod_time":
412
541
        $parse_result->mod_time = $text;
413
542
        break;
424
553
}
425
554
 
426
555
 
427
 
// state of prefs for new users
 
556
// state of prefs before parsing; defines prefs for new users
428
557
//
429
558
function default_prefs_global() {
 
559
    global $cpu_prefs;
 
560
    global $disk_prefs;
 
561
    global $net_prefs;
 
562
 
430
563
    $p = null;
431
 
    $p->suspend_while_on_batteries = true;
432
 
    $p->suspend_if_user_active = false;
433
 
    $p->idle_time_to_run = 3;
434
 
    $p->suspend_if_no_recent_input = 0;
435
 
    $p->start_hour = 0;
436
 
    $p->end_hour = 0;
437
 
    $p->leave_apps_in_memory = false;
438
 
    $p->cpu_scheduling_period_minutes = 60;
439
 
    $p->confirm_before_connecting = false;
440
 
    $p->hangup_if_dialed = true;
441
 
    $p->work_buf_min_days = 0;
442
 
    $p->work_buf_additional_days = 0.25;
443
 
    $p->max_cpus = 16;
444
 
    $p->max_ncpus_pct = 100;
445
 
    $p->cpu_usage_limit = 100;
446
 
    $p->disk_interval = 60;
447
 
    $dp = get_disk_space_config();
448
 
    $p->disk_max_used_gb = $dp->disk_max_used_gb;
449
 
    $p->disk_max_used_pct = $dp->disk_max_used_pct;
450
 
    $p->disk_min_free_gb = $dp->disk_min_free_gb;
451
 
    $p->vm_max_used_pct = 75;
452
 
    $p->ram_max_used_busy_pct = 50;
453
 
    $p->ram_max_used_idle_pct = 90;
454
 
    $p->max_bytes_sec_down = 0;
455
 
    $p->max_bytes_sec_up = 0;
456
 
    $p->net_start_hour = 0;
457
 
    $p->net_end_hour = 0;
458
 
    $p->dont_verify_images = false;
 
564
    foreach ($cpu_prefs as $pref) {
 
565
        $pref->set_default($p);
 
566
    }
 
567
    foreach ($disk_prefs as $pref) {
 
568
        $pref->set_default($p);
 
569
    }
 
570
    foreach ($net_prefs as $pref) {
 
571
        $pref->set_default($p);
 
572
    }
459
573
    return $p;
460
574
}
461
575
 
462
576
function default_prefs_project() {
 
577
    global $project_pref_descs;
 
578
 
463
579
    $p = null;
464
 
    $p->resource_share = 100;
465
 
    $p->allow_beta_work = false;
466
 
    $p->allow_beta_work_text = "no";
 
580
    foreach($project_pref_descs as $pref) {
 
581
        $pref->set_default($p);
 
582
    }
467
583
    $p->project_specific = project_specific_prefs_default();
468
584
    return $p;
469
585
}
470
586
 
471
 
// state of prefs before parsing; initialize booleans
472
 
//
473
 
function initialize_prefs_before_parsing_global() {
474
 
    $p = default_prefs_global();
475
 
    $p->suspend_while_on_batteries = true;
476
 
    $p->suspend_if_user_active = true;
477
 
    $p->leave_apps_in_memory = false;
478
 
    $p->confirm_before_connecting = false;
479
 
    $p->hangup_if_dialed = false;
480
 
    $p->dont_verify_images = false;
481
 
    
482
 
    return $p;
483
 
}
484
 
 
485
 
function initialize_prefs_before_parsing_project() {
486
 
    $p = default_prefs_project();
487
 
    return $p;
488
 
}
489
 
 
490
587
// parse prefs from XML to a struct
491
588
//
492
589
function prefs_parse_project($prefs_xml) {
493
590
    global $parse_result;
494
 
    $parse_result = initialize_prefs_before_parsing_project();
 
591
    $parse_result = default_prefs_project();
495
592
    $xml_parser = xml_parser_create();
496
593
    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
497
594
    xml_set_element_handler($xml_parser, "element_start_project", "element_end_project");
502
599
 
503
600
function prefs_parse_global($prefs_xml) {
504
601
    global $parse_result;
505
 
    $parse_result = initialize_prefs_before_parsing_global();
506
 
    //echo "AFTER INIT: <pre>";
507
 
    //var_dump($parse_result);
508
 
    //echo "</pre>";
 
602
    $parse_result = default_prefs_global();
509
603
    $xml_parser = xml_parser_create();
510
604
    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
511
605
    xml_set_element_handler($xml_parser, "element_start_global", "element_end_global");
512
606
    xml_set_character_data_handler($xml_parser, "char_handler");
513
607
    xml_parse($xml_parser, $prefs_xml, 1);
514
 
    //echo "AFTER PARSE: <pre>";
515
 
    //var_dump($parse_result);
516
 
    //echo "</pre>";
517
608
    return $parse_result;
518
609
}
519
610
 
520
 
function hour_str($x) {
521
 
    return "$x:00";
522
 
}
523
 
 
524
 
function hour_select($x, $name) {
525
 
    $s = "";
526
 
    $s = $s. "<select name=$name>\n";
527
 
    for ($i=0; $i<24; $i++) {
528
 
        $y = hour_str($i);
529
 
        $sel = ($x == $i)?"selected":"";
530
 
        $s = $s."<option value=$i $sel> $y";
531
 
    }
532
 
    $s = $s."</select>\n";
533
 
    return $s;
534
 
}
535
 
 
536
611
////////////////////////////////////////////
537
612
//
538
613
// display preference subsets as Columns
539
614
//
540
615
function row_top($x, $ncols=6, $class="heading") {
541
616
    echo "<tr><td class=$class width=35%>$x</td>";
542
 
    echo "<td class=$class width=10%><b>Default</b></td>
543
 
        <td class=$class width=10%><b>Home</b></td>
544
 
        <td class=$class width=10%><b>School</b></td>
545
 
        <td class=$class width=10%><b>Work</b></td>";
 
617
    echo "<td class=$class width=10%><b>".tra("Default")."</b></td>
 
618
        <td class=$class width=10%><b>".tra("Home")."</b></td>
 
619
        <td class=$class width=10%><b>".tra("School")."</b></td>
 
620
        <td class=$class width=10%><b>".tra("Work")."</b></td>";
546
621
    echo "<td width=15%><br></td></tr>\n";
547
622
}
548
623
 
549
624
//
550
 
// hour_range - Produce range string for given venue
551
 
//
552
 
function hour_range($venue, $type) {
553
 
    if ($type == "run") {
554
 
        $s_hour = $venue->start_hour;
555
 
        $e_hour = $venue->end_hour;
556
 
    }
557
 
    if ($type == "net") {
558
 
        $s_hour = $venue->net_start_hour;
559
 
        $e_hour = $venue->net_end_hour;
560
 
    }
561
 
    if ($s_hour == $e_hour) {
562
 
        $x = "--";
563
 
    } else {
564
 
        $s = hour_str($s_hour);
565
 
        $e = hour_str($e_hour);
566
 
        $x = "$s<br>to $e";
567
 
    }
568
 
    return $x;
569
 
}
570
 
 
571
 
//
572
625
// row_defs - Display a value for all 4 venues in one row
573
626
//
574
627
function row_defs($pre, $item, $post, $type, $prefs) {
575
628
    $gen = $prefs->$item;
576
 
    $hom  = isset($prefs->home) ? $prefs->home->$item : "--";
577
 
    $schl = isset($prefs->school) ? $prefs->school->$item : "--";
578
 
    $wrk  = isset($prefs->work) ? $prefs->work->$item : "--";
 
629
    $hom  = (isset($prefs->home) && isset($prefs->home->$item)) ? $prefs->home->$item : "--";
 
630
    $schl = (isset($prefs->school) && isset($prefs->school->$item)) ? $prefs->school->$item : "--";
 
631
    $wrk  = (isset($prefs->work) && isset($prefs->work->$item)) ? $prefs->work->$item : "--";
579
632
 
580
633
    echo "<tr><td class=fieldname>$pre</td>";
581
634
    row_field($gen,  $type);
586
639
}
587
640
 
588
641
//
589
 
// row_hours - Display start & end hours for all venues in 1 row
590
 
//
591
 
function row_hours($pre, $type, $global_prefs) {
592
 
    $gen = hour_range($global_prefs, $type);
593
 
    $hom  = isset($global_prefs->home)   ? hour_range($global_prefs->home, $type)   : "--";
594
 
    $schl = isset($global_prefs->school) ? hour_range($global_prefs->school, $type) : "--";
595
 
    $wrk  = isset($global_prefs->work)   ? hour_range($global_prefs->work, $type)   : "--";
596
 
 
597
 
    echo "<tr><td class=fieldname>$pre</td>";
598
 
    row_field($gen, "");
599
 
    row_field($hom, "");
600
 
    row_field($schl, "");
601
 
    row_field($wrk, "");
602
 
    echo "<td class=f_val><br></td></tr>\n";
603
 
}
604
 
 
605
 
//
606
642
// row_field - Display each field value, with selectable display modes
607
643
//
608
644
function row_field($value, $type) {
610
646
    $type = $value === "--" ? "--" : $type;
611
647
    switch($type) {
612
648
    case "yesno":
613
 
        echo $value ?"yes":"no";
 
649
        echo $value ?tra("yes"):tra("no");
 
650
        break;
 
651
    case "noyes":
 
652
        echo $value ?tra("no"):tra("yes");
614
653
        break;
615
654
    case "limit":
616
655
        $x = max_bytes_display_mode($value);
617
656
        $y = "$x " . BYTE_ABBR;
618
 
        echo $x ? "$y" : "no limit";
 
657
        echo $x ? "$y" : tra("no limit");
619
658
        break;
620
659
    case "minutes":
621
660
        if ($value) {
640
679
    $pre_add  = "<a href=add_venue.php?venue=";
641
680
    $pre_edit  = "<a href=prefs_edit.php?venue=";
642
681
    $pre_remove = "<a href=prefs_remove.php?venue=";
643
 
    $post_add = "&subset=$subset&cols=1$tokens>Add</a>";
644
 
    $post_edit = "&subset=$subset&cols=1$tokens>Edit</a>";
645
 
    $post_remove = "&subset=$subset&cols=1$tokens>Remove</a>";
646
 
    $gen = "<a href=prefs_edit.php?subset=$subset&cols=1$tokens>Edit</a>";
 
682
    $post_add = "&amp;subset=$subset&cols=1$tokens>".tra("Add")."</a>";
 
683
    $post_edit = "&amp;subset=$subset&cols=1$tokens>".tra("Edit")."</a>";
 
684
    $post_remove = "&amp;subset=$subset&cols=1$tokens>".tra("Remove")."</a>";
 
685
    $gen = "<a href=prefs_edit.php?subset=$subset&amp;cols=1$tokens>".tra("Edit")."</a>";
647
686
 
648
687
    $hom  = isset($prefs->home) ? $pre_edit."home".$post_edit : $pre_add."home".$post_add;
649
688
    $schl = isset($prefs->school) ? $pre_edit."school".$post_edit : $pre_add."school".$post_add;
668
707
    echo "<td><br></td></tr>\n";
669
708
}
670
709
 
671
 
 
672
 
//
673
 
// prefs_show_columns_global - Display all venues as columns next to descriptions
 
710
// Display all venues as columns next to descriptions
674
711
//
675
712
function prefs_show_columns_global($prefs) {
 
713
    global $cpu_prefs;
 
714
    global $disk_prefs;
 
715
    global $net_prefs;
 
716
 
676
717
    row_top(CPU_LIMIT_DESC);
677
 
    row_defs(SUSPEND_WHILE_ON_BATTERIES_DESC, "suspend_while_on_batteries", "", "yesno", $prefs);
678
 
    row_defs(RUN_IF_USER_ACTIVE_DESC, "suspend_if_user_active", "", "yesno", $prefs);
679
 
    row_defs(IDLE_TIME_TO_RUN_DESC, "idle_time_to_run", " minutes", "", $prefs);
680
 
 
681
 
    row_defs(SUSPEND_IF_NO_RECENT_INPUT_DESC, "suspend_if_no_recent_input", "minutes", "minutes", $prefs);
682
 
 
683
 
    row_hours(START_END_DESC, "run", $prefs);
684
 
 
685
 
    row_defs(LEAVE_APPS_IN_MEMORY_DESC, "leave_apps_in_memory", "", "yesno", $prefs);
686
 
    row_defs(CPU_SCHEDULING_DESC, "cpu_scheduling_period_minutes", " minutes", "", $prefs);
687
 
    row_defs(MAX_CPUS_DESC, "max_cpus", MAX_CPUS_DESC2, "", $prefs);
688
 
    row_defs(MAX_NCPUS_PCT_DESC, "max_ncpus_pct", MAX_NCPUS_PCT_DESC2, "", $prefs);
689
 
    row_defs(USE_AT_MOST2, "cpu_usage_limit", CPU_USAGE_LIMIT_DESC2, "", $prefs);
690
 
 
 
718
    foreach ($cpu_prefs as $p) {
 
719
        $p->show_cols($prefs);
 
720
    }
691
721
    row_top(DISK_LIMIT_DESC);
692
 
    row_defs(USE_AT_MOST, "disk_max_used_gb", " GB disk space", "", $prefs);
693
 
    row_defs(DISK_MIN_FREE_GB_DESC, "disk_min_free_gb", " GB disk space free", "", $prefs);
694
 
    row_defs(USE_AT_MOST, "disk_max_used_pct", DISK_MAX_USED_PCT_DESC2, "", $prefs);
695
 
    row_defs(DISK_INTERVAL_DESC, "disk_interval", " seconds", "", $prefs);
696
 
    row_defs(USE_AT_MOST, "vm_max_used_pct", VM_MAX_USED_PCT_DESC2, "", $prefs);
697
 
    row_defs(USE_AT_MOST3, "ram_max_used_busy_pct", RAM_MAX_USED_BUSY_PCT_DESC2, "", $prefs);
698
 
    row_defs(USE_AT_MOST3, "ram_max_used_idle_pct", RAM_MAX_USED_IDLE_PCT_DESC2, "", $prefs);
699
 
 
 
722
    foreach ($disk_prefs as $p) {
 
723
        $p->show_cols($prefs);
 
724
    }
700
725
    row_top(NETWORK_LIMIT_DESC);
701
 
    row_defs(WORK_BUF_MIN_DAYS_DESC, "work_buf_min_days", " days", "", $prefs);
702
 
    row_defs(WORK_BUF_ADDITIONAL_DAYS_DESC, "work_buf_additional_days", " days", "", $prefs);
703
 
    row_defs(CONFIRM_BEFORE_CONNECTING_DESC, "confirm_before_connecting", "", "yesno", $prefs);
704
 
    row_defs(HANGUP_IF_DIALED_DESC, "hangup_if_dialed", "", "yesno", $prefs);
705
 
    row_defs(MAX_BYTES_SEC_DOWN_DESC, "max_bytes_sec_down", "", "limit", $prefs);
706
 
    row_defs(MAX_BYTES_SEC_UP_DESC, "max_bytes_sec_up", "", "limit", $prefs);
707
 
    row_hours(NET_START_END_DESC, "net", $prefs);
708
 
    row_defs(DONT_VERIFY_IMAGES_DESC, "dont_verify_images", "", "yesno", $prefs);
709
 
 
 
726
    foreach ($net_prefs as $p) {
 
727
        $p->show_cols($prefs);
 
728
    }
710
729
    row_links("global", $prefs);
711
730
}
712
731
 
713
 
function show_double($x) {
714
 
    if ($x) return $x;
715
 
    return '---';
716
 
}
717
 
 
718
732
function prefs_show_global($prefs) {
 
733
    global $cpu_prefs;
 
734
    global $disk_prefs;
 
735
    global $net_prefs;
 
736
 
719
737
    row1(CPU_LIMIT_DESC);
720
 
    row2(SUSPEND_WHILE_ON_BATTERIES_DESC, $prefs->suspend_while_on_batteries?"yes":"no");
721
 
    row2(RUN_IF_USER_ACTIVE_DESC, $prefs->suspend_if_user_active?"yes":"no");
722
 
    row2(IDLE_TIME_TO_RUN_DESC, "$prefs->idle_time_to_run minutes");
723
 
 
724
 
    $x = show_double($prefs->suspend_if_no_recent_input);
725
 
    row2(SUSPEND_IF_NO_RECENT_INPUT_DESC, "$x minutes");
726
 
 
727
 
    if ($prefs->start_hour == $prefs->end_hour) {
728
 
        $x = "(no restriction)";
729
 
    } else {
730
 
        $s = hour_str($prefs->start_hour);
731
 
        $e = hour_str($prefs->end_hour);
732
 
        $x = "$s and $e";
 
738
    foreach ($cpu_prefs as $p) {
 
739
        $p->show($prefs);
733
740
    }
734
 
    row2(START_END_DESC, $x);
735
 
    row2(LEAVE_APPS_IN_MEMORY_DESC, $prefs->leave_apps_in_memory?"yes":"no");
736
 
    row2(CPU_SCHEDULING_DESC, "$prefs->cpu_scheduling_period_minutes minutes");
737
 
    $x = $prefs->max_cpus?$prefs->max_cpus:'---';
738
 
    row2(MAX_CPUS_DESC, "$x ".MAX_CPUS_DESC2);
739
 
    $x = $prefs->max_ncpus_pct?$prefs->max_ncpus_pct:'---';
740
 
    row2(MAX_NCPUS_PCT_DESC, "$x ".MAX_NCPUS_PCT_DESC2);
741
 
    row2(USE_AT_MOST2, "$prefs->cpu_usage_limit ".CPU_USAGE_LIMIT_DESC2);
742
741
    row1(DISK_LIMIT_DESC);
743
 
    row2(USE_AT_MOST, "$prefs->disk_max_used_gb GB disk space");
744
 
 
745
 
    $dp = get_disk_space_config();
746
 
 
747
 
    $msg = null;
748
 
    if ($dp->new_sched_flag) {
749
 
        $msg = DISK_SCHED_MIN_FREE_DESC1.$dp->sched_disk_min_free_gb.DISK_SCHED_MIN_FREE_DESC2;
 
742
    foreach ($disk_prefs as $p) {
 
743
        $p->show($prefs);
750
744
    }
751
 
    row2(DISK_MIN_FREE_GB_DESC.$msg, "$prefs->disk_min_free_gb GB disk space free");
752
 
    row2(USE_AT_MOST, "$prefs->disk_max_used_pct".DISK_MAX_USED_PCT_DESC2);
753
 
    row2(DISK_INTERVAL_DESC, "$prefs->disk_interval seconds");
754
 
    row2(USE_AT_MOST, "$prefs->vm_max_used_pct".VM_MAX_USED_PCT_DESC2);
755
 
    row2(USE_AT_MOST3, "$prefs->ram_max_used_busy_pct".RAM_MAX_USED_BUSY_PCT_DESC2);
756
 
    row2(USE_AT_MOST3, "$prefs->ram_max_used_idle_pct".RAM_MAX_USED_IDLE_PCT_DESC2);
757
745
    row1(NETWORK_LIMIT_DESC);
758
 
    row2(WORK_BUF_MIN_DAYS_DESC, "$prefs->work_buf_min_days days");
759
 
    row2(WORK_BUF_ADDITIONAL_DAYS_DESC, "$prefs->work_buf_additional_days days");
760
 
    row2(CONFIRM_BEFORE_CONNECTING_DESC, $prefs->confirm_before_connecting?"yes":"no");
761
 
    row2(HANGUP_IF_DIALED_DESC, $prefs->hangup_if_dialed?"yes":"no");
762
 
    $x = max_bytes_display_mode($prefs->max_bytes_sec_down);
763
 
    $y = "$x " . BYTE_ABBR;
764
 
    row2(MAX_BYTES_SEC_DOWN_DESC, $x?"$y":"no limit");
765
 
    $x = max_bytes_display_mode($prefs->max_bytes_sec_up);
766
 
    $y = "$x " . BYTE_ABBR;
767
 
    row2(MAX_BYTES_SEC_UP_DESC, $x?"$y":"no limit");
768
 
    if ($prefs->net_start_hour == $prefs->net_end_hour) {
769
 
        $x = "(no restriction)";
770
 
    } else {
771
 
        $s = hour_str($prefs->net_start_hour);
772
 
        $e = hour_str($prefs->net_end_hour);
773
 
        $x = "$s and $e";
774
 
    }
775
 
    row2(NET_START_END_DESC, $x);
776
 
    row2(DONT_VERIFY_IMAGES_DESC, $prefs->dont_verify_images?"yes":"no");
777
 
}
778
 
 
779
 
function prefs_show_resource($prefs, $columns=false) {
780
 
    $x = "Resource share<br>
781
 
        <span class=note>If you participate in multiple BOINC projects,
782
 
        this is the proportion of your resources used by ".PROJECT."</span>";
783
 
    if ($columns) {
784
 
        row_defs($x, "resource_share", "", "" ,$prefs);
785
 
    } else {
786
 
        row2($x, $prefs->resource_share);
787
 
    }
788
 
}
789
 
 
790
 
function prefs_show_beta($prefs, $columns=false) {
791
 
    if ($columns) {
792
 
        row_defs(ALLOW_BETA_WORK, "allow_beta_work_text", "", "" ,$prefs);
793
 
    } else {
794
 
        row2(ALLOW_BETA_WORK, $prefs->allow_beta_work_text);
795
 
    }
796
 
}
797
 
 
798
 
function prefs_show_privacy($user) {
799
 
    $x = "";
800
 
    if (defined('EMAIL_FROM')) {
801
 
        $x = "<br><span class=note>Emails will be sent from ".EMAIL_FROM.";
802
 
            make sure your spam filter accepts this address.</span>";
803
 
    }
804
 
    row2("Is it OK for ".PROJECT." and your team (if any) to email you? $x",
805
 
        $user->send_email?"yes":"no"
806
 
    );
807
 
    row2("Should ".PROJECT." show your computers on its web site?", $user->show_hosts?"yes":"no");
 
746
    foreach ($net_prefs as $p) {
 
747
        $p->show($prefs);
 
748
    }
808
749
}
809
750
 
810
751
function prefs_show_project($prefs, $columns=false) {
 
752
    global $project_pref_descs;
 
753
    if ($columns) {
 
754
        foreach ($project_pref_descs as $p) {
 
755
            $p->show_cols($prefs);
 
756
        }
 
757
    } else {
 
758
        foreach ($project_pref_descs as $p) {
 
759
            $p->show($prefs);
 
760
        }
 
761
    }
 
762
}
 
763
 
 
764
function prefs_show_privacy($user, $columns) {
 
765
    global $privacy_pref_descs;
 
766
    if ($columns) {
 
767
        foreach ($privacy_pref_descs as $p) {
 
768
            $p->show_cols($user);
 
769
        }
 
770
    } else {
 
771
        foreach ($privacy_pref_descs as $p) {
 
772
            $p->show($user);
 
773
        }
 
774
    }
 
775
}
 
776
 
 
777
function prefs_show_project_specific($prefs, $columns=false) {
811
778
    if ($columns) {
812
779
    $project_specific_prefs = project_specific_prefs_parse($prefs->project_specific);
813
780
        $project_specific_prefs->home = isset($prefs->home) ? project_specific_prefs_parse($prefs->home->project_specific) : "";
820
787
}
821
788
 
822
789
function subset_name($subset) {
823
 
    if ($subset == "global") return "Computing";
 
790
    if ($subset == "global") return tra("Computing");
824
791
    return PROJECT;
825
792
}
826
793
 
827
794
function prefs_display_venue($prefs, $venue, $subset) {
828
 
    global $project_has_beta;
829
795
    global $g_logged_in_user;
830
796
    $tokens = url_tokens($g_logged_in_user->authenticator);
831
797
    $x = false;
832
798
    if (isset($prefs->$venue)) $x = $prefs->$venue;
833
799
 
834
800
    if ($x) {
835
 
        row1("Separate preferences for $venue", 2, "heading");
 
801
        row1(tra("Separate preferences for %1", $venue), 2, "heading");
836
802
        echo "<tr><td colspan=2>";
837
803
        start_table();
838
804
        if ($subset == "global") {
839
805
            prefs_show_global($x);
840
806
        } else {
841
 
            prefs_show_resource($x);
842
 
            if ($project_has_beta) prefs_show_beta($x);
843
807
            prefs_show_project($x);
 
808
            prefs_show_project_specific($x);
844
809
        }
845
 
        row2("<br>", "<a href=prefs_edit.php?venue=$venue&subset=$subset$tokens>Edit preferences</a> | <a href=prefs_remove.php?venue=$venue&subset=$subset$tokens>Remove</a>");
 
810
        row2("<br>", "<a href=prefs_edit.php?venue=$venue&amp;subset=$subset$tokens>".tra("Edit preferences")."</a> | <a href=prefs_remove.php?venue=$venue&amp;subset=$subset$tokens>".tra("Remove")."</a>");
846
811
        end_table();
847
812
        echo "</td></tr>\n";
848
813
    } else {
849
 
        //$x = subset_name($subset);
850
 
        row1("<a href=add_venue.php?venue=$venue&subset=$subset$tokens>Add separate preferences for $venue</a>", 2, "heading");
 
814
        row1("<a href=add_venue.php?venue=$venue&amp;subset=$subset$tokens>".tra("Add separate preferences for %1", $venue)."</a>", 2, "heading");
851
815
    }
852
816
}
853
817
 
854
818
function print_prefs_display_project($user, $columns=false) {
855
 
    global $project_has_beta;
856
819
    $project_prefs = prefs_parse_project($user->project_prefs);
857
820
 
858
821
    start_table();
859
 
    $switch_link = " <font size=\"-2\"><a href=prefs.php?subset=project&cols=". (int)!$columns .">(Switch View)</a></font>";
 
822
    $switch_link = " <font size=\"-2\"><a href=prefs.php?subset=project&cols=". (int)!$columns .">".tra("(Switch View)")."</a></font>";
860
823
    if ($columns) {
861
 
        row1("Combined preferences".$switch_link, 2, "heading");
 
824
        row1(tra("Combined preferences").$switch_link, 2, "heading");
862
825
        echo "<tr><td colspan=2>";
863
826
        start_table();
864
 
        prefs_show_privacy($user);
 
827
        prefs_show_privacy($user, true);
865
828
        venue_show($user);
866
 
        row_top("Project specific settings");
867
 
        prefs_show_resource($project_prefs, true);
868
 
        if ($project_has_beta) prefs_show_beta($project_prefs, true);
 
829
        row_top(tra("Project specific settings"));
869
830
        prefs_show_project($project_prefs, true);
 
831
        prefs_show_project_specific($project_prefs, true);
870
832
        row_links("project", $project_prefs);
871
833
        end_table();
872
834
        echo "</td></tr>\n";
873
835
    } else {
874
836
        if (isset($project_prefs->home) || isset($project_prefs->work) || isset($project_prefs->school)) {
875
 
            row1("Primary (default) preferences".$switch_link, 2, "heading");
 
837
            row1(tra("Primary (default) preferences").$switch_link, 2, "heading");
876
838
        }
877
839
        echo "<tr><td colspan=2>";
878
840
        start_table();
879
 
        prefs_show_resource($project_prefs, false);
880
 
        if ($project_has_beta) prefs_show_beta($project_prefs, false);
881
 
        prefs_show_privacy($user);
882
 
        venue_show($user);
883
841
        prefs_show_project($project_prefs, false);
 
842
        prefs_show_privacy($user, false);
 
843
        venue_show($user);
 
844
        prefs_show_project_specific($project_prefs, false);
884
845
        $tokens = url_tokens($user->authenticator);
885
 
        row2("", "<a href=prefs_edit.php?subset=project$tokens>Edit ".PROJECT." preferences</a>");
 
846
        row2("", "<a href=prefs_edit.php?subset=project$tokens>".tra("Edit %1 preferences", PROJECT)."</a>");
886
847
        end_table();
887
848
        echo "</td></tr>\n";
888
849
        prefs_display_venue($project_prefs, "home", "project");
895
856
function print_prefs_display_global($user, $columns=false) {
896
857
    $global_prefs = prefs_parse_global($user->global_prefs);
897
858
 
898
 
    echo "<span class=note>
899
 
        These apply to all BOINC projects in which you participate.
900
 
        <br>
901
 
        On computers attached to multiple projects,
902
 
        the most recently modified preferences will be used.
903
 
        </span>
904
 
        <br><br>
905
 
    ";
 
859
    echo "<span class=note>".
 
860
         tra("These apply to all BOINC projects in which you participate.<br>
 
861
             On computers participating in multiple projects, the most recently modified preferences will be used.").
 
862
         "</span><br><br>";
906
863
    if (isset($global_prefs->mod_time)) {
907
 
        echo "
908
 
            Preferences last modified: ", pretty_time_str($global_prefs->mod_time), "
909
 
        ";
 
864
        echo tra("Preferences last modified:")." ".pretty_time_str($global_prefs->mod_time);
910
865
    }
911
 
    echo "
912
 
        <br><br>
913
 
    ";
914
 
    $switch_link = " <font size=\"-2\"><a href=prefs.php?subset=global&cols=". (int)!$columns .">(Switch View)</a></font>";
 
866
    echo "<br><br>";
 
867
    $switch_link = " <font size=\"-2\"><a href=prefs.php?subset=global&cols=". (int)!$columns .">".tra("(Switch View)")."</a></font>";
915
868
    start_table();
916
869
    if ($columns) {
917
 
        row1("Combined preferences".$switch_link, 2, "heading");
 
870
        row1(tra("Combined preferences").$switch_link, 2, "heading");
918
871
        echo "<tr><td colspan=2>";
919
872
        start_table();
920
873
        prefs_show_columns_global($global_prefs);
923
876
 
924
877
    } else {
925
878
        if (isset($global_prefs->home) || isset($global_prefs->work) || isset($global_prefs->school)) {
926
 
            row1("Primary (default) preferences".$switch_link, 2, "heading");
 
879
            row1(tra("Primary (default) preferences").$switch_link, 2, "heading");
927
880
        }
928
881
        echo "<tr><td colspan=2>";
929
882
        start_table();
930
883
        prefs_show_global($global_prefs);
931
884
        $tokens = url_tokens($user->authenticator);
932
 
        row2("<br>", "<a href=prefs_edit.php?subset=global$tokens>Edit preferences</a>");
 
885
        row2("<br>", "<a href=prefs_edit.php?subset=global$tokens>".tra("Edit preferences")."</a>");
933
886
        end_table();
934
887
        echo "</td></tr>\n";
935
888
 
956
909
    $action, $subset, $venue, $user, $prefs, $cols, $error=false,
957
910
    $project_error=false
958
911
){
959
 
    global $project_has_beta;
960
 
 
961
912
    if ($action == "add") {
962
913
        $script = "add_venue.php";
963
 
        $submit_value = "Add preferences";
 
914
        $submit_value = tra("Add preferences");
964
915
    }
965
916
    if ($action == "edit") {
966
917
        $script = "prefs_edit.php";
967
 
        $submit_value = "Update preferences";
 
918
        $submit_value = tra("Update preferences");
968
919
    }
969
920
    echo "<form action=$script><input type=hidden name=subset value=$subset>
970
921
        ".form_tokens($user->authenticator);
979
930
    if ($subset == "global") {
980
931
        prefs_form_global($user, $prefs, $error);
981
932
    } else {
982
 
        prefs_form_resource($prefs, $error);
983
 
        if ($project_has_beta) prefs_form_beta($prefs, $error);
 
933
        prefs_form_project($prefs, $error);
984
934
        if (!$venue) {
985
935
            prefs_form_privacy($user);
986
936
            venue_form($user);
987
937
        }
988
 
        prefs_form_project($prefs->project_specific, $project_error);
 
938
        prefs_form_project_specific($prefs->project_specific, $project_error);
989
939
    }
990
940
 
991
 
    row2("<br>", "<input type=submit value=\"$submit_value\" name=\"action\">");
 
941
    row2("", "<input type=submit value=\"$submit_value\" name=\"action\">");
992
942
    end_table();
993
943
    echo "</form>\n";
994
944
}
998
948
// Functions to display preference subsets as forms
999
949
//
1000
950
function prefs_form_global($user, $prefs, $error=false) {
1001
 
    //echo "IN PREFS_FORM_GLOBAL: <pre>";
1002
 
    //var_dump($prefs);
1003
 
    //echo "</pre>";
 
951
    global $cpu_prefs;
 
952
    global $disk_prefs;
 
953
    global $net_prefs;
 
954
 
1004
955
    row1(CPU_LIMIT_DESC);
1005
 
    $y = "yes <input type=radio name=suspend_while_on_batteries value=yes "
1006
 
        .($prefs->suspend_while_on_batteries?"checked":"")
1007
 
        ."> no <input type=radio name=suspend_while_on_batteries value=no "
1008
 
        .($prefs->suspend_while_on_batteries?"":"checked")
1009
 
        .">
1010
 
    ";
1011
 
    row2(SUSPEND_WHILE_ON_BATTERIES_DESC, $y);
1012
 
 
1013
 
    $y = "yes <input type=radio name=suspend_if_user_active value=yes "
1014
 
        .($prefs->suspend_if_user_active?"checked":"")
1015
 
        ."> no <input type=radio name=suspend_if_user_active value=no "
1016
 
        .($prefs->suspend_if_user_active?"":"checked")
1017
 
        .">
1018
 
    ";
1019
 
    row2(RUN_IF_USER_ACTIVE_DESC, $y);
1020
 
 
1021
 
    $y = "<input size=5 name=idle_time_to_run value='$prefs->idle_time_to_run'> minutes ";
1022
 
    $show_error = false;
1023
 
    if (isset($error->idle_time_to_run)) $show_error= true;
1024
 
    row2(IDLE_TIME_TO_RUN_DESC, $y, $show_error);
1025
 
 
1026
 
    $y = "<input size=5 name=suspend_if_no_recent_input value='$prefs->suspend_if_no_recent_input'> minutes ";
1027
 
    $show_error = false;
1028
 
    if (isset($error->suspend_if_no_recent_input)) $show_error= true;
1029
 
    row2(SUSPEND_IF_NO_RECENT_INPUT_DESC, $y, $show_error);
1030
 
 
1031
 
    $x = START_END_DESC.START_END_DESC2;
1032
 
    $y = hour_select($prefs->start_hour, "start_hour")."and".hour_select($prefs->end_hour, "end_hour");
1033
 
    row2($x, $y);
1034
 
 
1035
 
    $x = LEAVE_APPS_IN_MEMORY_DESC;
1036
 
    $y = "yes <input type=radio name=leave_apps_in_memory value=yes "
1037
 
        .($prefs->leave_apps_in_memory?"checked":"")
1038
 
        ."> no <input type=radio name=leave_apps_in_memory value=no "
1039
 
        .($prefs->leave_apps_in_memory?"":"checked")
1040
 
        .">
1041
 
    ";
1042
 
    row2($x, $y);
1043
 
 
1044
 
    $y = "<input size=5 name=cpu_scheduling_period_minutes value='$prefs->cpu_scheduling_period_minutes'> minutes ";
1045
 
    $show_error = false;
1046
 
    if (isset($error->cpu_scheduling_period_minutes)) $show_error= true;
1047
 
    row2(CPU_SCHEDULING_DESC, $y, $show_error);
1048
 
 
1049
 
    $show_error = false;
1050
 
    if (isset($error->max_cpus)) $show_error= true;
1051
 
    row2(MAX_CPUS_DESC,
1052
 
        "<input size=4 name=max_cpus value=$prefs->max_cpus> ".MAX_CPUS_DESC2,
1053
 
        $show_error
1054
 
    );
1055
 
 
1056
 
    $show_error = false;
1057
 
    if (isset($error->max_ncpus_pct)) $show_error= true;
1058
 
    row2(MAX_NCPUS_PCT_DESC,
1059
 
        "<input size=4 name=max_ncpus_pct value=$prefs->max_ncpus_pct> ".MAX_NCPUS_PCT_DESC2,
1060
 
        $show_error
1061
 
    );
1062
 
 
1063
 
    $show_error = false;
1064
 
    if (isset($error->cpu_usage_limit)) $show_error= true;
1065
 
    row2(USE_AT_MOST2,
1066
 
        "<input size=4 name=cpu_usage_limit value=$prefs->cpu_usage_limit> ".CPU_USAGE_LIMIT_DESC2,
1067
 
        $show_error
1068
 
    );
1069
 
 
 
956
    foreach ($cpu_prefs as $p) {
 
957
        $p->show_form_row($prefs, $error);
 
958
    }
1070
959
    row1(DISK_LIMIT_DESC);
1071
 
 
1072
 
    $show_error = false;
1073
 
    if (isset($error->disk_max_used_gb)) $show_error= true;
1074
 
    row2(USE_AT_MOST,
1075
 
        "<input size=7 name=disk_max_used_gb value='$prefs->disk_max_used_gb'> Gbytes",
1076
 
        $show_error
1077
 
    );
1078
 
 
1079
 
    $dp = get_disk_space_config();
1080
 
 
1081
 
    $msg=null;
1082
 
    if ($dp->new_sched_flag) {
1083
 
        $msg = DISK_SCHED_MIN_FREE_DESC1.$dp->sched_disk_min_free_gb.DISK_SCHED_MIN_FREE_DESC2;
1084
 
    } 
1085
 
 
1086
 
    $show_error = false;
1087
 
    if (isset($error->disk_min_free_gb)) $show_error= true;
1088
 
    row2(DISK_MIN_FREE_GB_DESC.$msg,
1089
 
        "<input size=7 name=disk_min_free_gb value='$prefs->disk_min_free_gb'> Gbytes free",
1090
 
        $show_error
1091
 
    );
1092
 
 
1093
 
    $show_error = false;
1094
 
    if (isset($error->disk_max_used_pct)) $show_error= true;
1095
 
    row2(USE_AT_MOST,
1096
 
        "<input size=5 name=disk_max_used_pct value='$prefs->disk_max_used_pct'> ".DISK_MAX_USED_PCT_DESC2,
1097
 
        $show_error
1098
 
    );
1099
 
 
1100
 
    $show_error = false;
1101
 
    if (isset($error->disk_interval)) $show_error= true;
1102
 
    row2(DISK_INTERVAL_DESC,
1103
 
        "<input size=6 name=disk_interval value=$prefs->disk_interval> seconds",
1104
 
        $show_error
1105
 
    );
1106
 
 
1107
 
    $show_error = false;
1108
 
    if (isset($error->vm_max_used_pct)) $show_error= true;
1109
 
    row2(USE_AT_MOST,
1110
 
        "<input size=5 name=vm_max_used_pct value='$prefs->vm_max_used_pct'> ".VM_MAX_USED_PCT_DESC2,
1111
 
        $show_error
1112
 
    );
1113
 
 
1114
 
    $show_error = false;
1115
 
    if (isset($error->ram_max_used_busy_pct)) $show_error= true;
1116
 
    row2(USE_AT_MOST3,
1117
 
        "<input size=5 name=ram_max_used_busy_pct value='$prefs->ram_max_used_busy_pct'> ".RAM_MAX_USED_BUSY_PCT_DESC2,
1118
 
        $show_error
1119
 
    );
1120
 
 
1121
 
    $show_error = false;
1122
 
    if (isset($error->ram_max_used_idle_pct)) $show_error= true;
1123
 
    row2(USE_AT_MOST3,
1124
 
        "<input size=5 name=ram_max_used_idle_pct value='$prefs->ram_max_used_idle_pct'> ".RAM_MAX_USED_IDLE_PCT_DESC2,
1125
 
        $show_error
1126
 
    );
1127
 
 
 
960
    foreach ($disk_prefs as $p) {
 
961
        $p->show_form_row($prefs, $error);
 
962
    }
1128
963
    row1(NETWORK_LIMIT_DESC);
1129
 
    $x = WORK_BUF_MIN_DAYS_DESC;
1130
 
    $y = "<input size=5 name=work_buf_min_days value='$prefs->work_buf_min_days'> days";
1131
 
    $show_error = false;
1132
 
    if (isset($error->work_buf_min_days)) $show_error= true;
1133
 
    row2($x, $y, $show_error);
1134
 
 
1135
 
    $x = WORK_BUF_ADDITIONAL_DAYS_DESC;
1136
 
    $y = "<input size=5 name=work_buf_additional_days value='$prefs->work_buf_additional_days'> days";
1137
 
    $show_error = false;
1138
 
    if (isset($error->work_buf_additional_days)) $show_error= true;
1139
 
    row2($x, $y, $show_error);
1140
 
 
1141
 
    $x = CONFIRM_BEFORE_CONNECTING_DESC;
1142
 
    $y = "yes <input type=radio name=confirm_before_connecting value=yes "
1143
 
        .($prefs->confirm_before_connecting?"checked":"")
1144
 
        ."> no <input type=radio name=confirm_before_connecting value=no "
1145
 
        .($prefs->confirm_before_connecting?"":"checked")
1146
 
        .">
1147
 
    ";
1148
 
    row2($x, $y);
1149
 
 
1150
 
    $x = HANGUP_IF_DIALED_DESC;
1151
 
    $y = "yes <input type=radio name=hangup_if_dialed value=yes "
1152
 
        .($prefs->hangup_if_dialed?"checked":"")
1153
 
        ."> no <input type=radio name=hangup_if_dialed value=no "
1154
 
        .($prefs->hangup_if_dialed?"":"checked")
1155
 
        .">
1156
 
    ";
1157
 
    row2($x, $y);
1158
 
 
1159
 
    $d = max_bytes_display_mode($prefs->max_bytes_sec_down);
1160
 
    $dt = $d?"$d":"";
1161
 
    $u = max_bytes_display_mode($prefs->max_bytes_sec_up);
1162
 
    $ut = $u?"$u":"";
1163
 
 
1164
 
    $show_error = false;
1165
 
    if (isset($error->max_bytes_sec_down)) $show_error= true;
1166
 
    row2(MAX_BYTES_SEC_DOWN_DESC,
1167
 
        "<input size=7 name=max_bytes_sec_down value='$dt'> " . BYTE_UNITS,
1168
 
        $show_error
1169
 
    );
1170
 
 
1171
 
    $show_error = false;
1172
 
    if (isset($error->max_bytes_sec_up)) $show_error= true;
1173
 
    row2(MAX_BYTES_SEC_UP_DESC,
1174
 
        "<input size=7 name=max_bytes_sec_up value='$ut'> " . BYTE_UNITS,
1175
 
        $show_error
1176
 
    );
1177
 
 
1178
 
    $x = NET_START_END_DESC.START_END_DESC2;
1179
 
    $y = hour_select($prefs->net_start_hour, "net_start_hour")."and".hour_select($prefs->net_end_hour, "net_end_hour");
1180
 
    row2($x, $y);
1181
 
    $x = DONT_VERIFY_IMAGES_DESC;
1182
 
    $y = "yes <input type=radio name=dont_verify_images value=yes "
1183
 
        .($prefs->dont_verify_images?"checked":"")
1184
 
        ."> no <input type=radio name=dont_verify_images value=no "
1185
 
        .($prefs->dont_verify_images?"":"checked")
1186
 
        .">
1187
 
    ";
1188
 
    row2($x, $y);
1189
 
 
 
964
    foreach ($net_prefs as $p) {
 
965
        $p->show_form_row($prefs, $error);
 
966
    }
1190
967
}
1191
968
 
1192
969
function prefs_form_privacy($user) {
1193
 
    $y = "yes <input type=radio name=send_email value=yes "
1194
 
        .($user->send_email?"checked":"")
1195
 
        ."> no <input type=radio name=send_email value=no "
1196
 
        .($user->send_email?"":"checked")
1197
 
        .">
1198
 
    ";
1199
 
    row2("Is it OK for ".PROJECT." and your team (if any) to email you?", $y);
1200
 
 
1201
 
    $y = "yes <input type=radio name=show_hosts value=yes "
1202
 
        .($user->show_hosts?"checked":"")
1203
 
        ."> no <input type=radio name=show_hosts value=no "
1204
 
        .($user->show_hosts?"":"checked")
1205
 
        .">
1206
 
    ";
1207
 
    row2("Should ".PROJECT." show your computers on its web site?", $y);
1208
 
}
1209
 
 
1210
 
function prefs_form_resource($prefs, $error=false) {
1211
 
    $show_error = false;
1212
 
    if (isset($error->resource_share)) $show_error= true;
1213
 
    row2(
1214
 
        "<b>Resource share:</b>
1215
 
        <span class=note><br>Determines the proportion of your computer's resources
1216
 
        allocated to this project.
1217
 
        Example: if you participate in two BOINC projects with
1218
 
        resource shares of 100 and 200,
1219
 
        the first will get 1/3 of your resources and the second will get 2/3.
1220
 
        </span>",
1221
 
        "<input name=resource_share value='$prefs->resource_share'>",
1222
 
        $show_error
1223
 
    );
1224
 
}
1225
 
 
1226
 
function prefs_form_beta($prefs, $error=false) {
1227
 
    $ychecked = $prefs->allow_beta_work?"checked":"";
1228
 
    $nchecked = $prefs->allow_beta_work?"":"checked";
1229
 
    row2(
1230
 
        ALLOW_BETA_WORK,
1231
 
        "yes <input type=radio checkbox name=allow_beta_work value=1 $ychecked>
1232
 
        no <input type=radio checkbox name=allow_beta_work value=0 $nchecked>"
1233
 
    );
1234
 
}
1235
 
 
1236
 
function prefs_form_project($prefs_xml, $error=false) {
 
970
    global $privacy_pref_descs;
 
971
    foreach ($privacy_pref_descs as $p) {
 
972
        $p->show_form_row($user, false);
 
973
    }
 
974
}
 
975
 
 
976
function prefs_form_project($prefs, $error=false) {
 
977
    global $project_pref_descs;
 
978
    foreach ($project_pref_descs as $p) {
 
979
        $p->show_form_row($prefs, $error);
 
980
    }
 
981
}
 
982
 
 
983
function prefs_form_project_specific($prefs_xml, $error=false) {
1237
984
    $prefs = project_specific_prefs_parse($prefs_xml);
1238
985
    project_specific_prefs_edit($prefs, $error);
1239
986
}
1240
987
 
 
988
// returns a set of translated yes/no radio buttons for editing prefs forms
 
989
// Example: prefs_form_radio_buttons("allow_beta_work", $user->allow_beta_work);
 
990
//
 
991
// @param string $name name of the radio buttons
 
992
// @param bool $yesno toggles the preset of the buttons; true=yes, false=no
 
993
//
 
994
function prefs_form_radio_buttons($name, $yesno) {
 
995
    $rb = tra("yes")." <input type=radio name=$name value=yes "
 
996
        .($yesno?"checked":"")
 
997
        ."> ".tra("no")." <input type=radio name=$name value=no "
 
998
        .($yesno?"":"checked")
 
999
        .">\n";
 
1000
    return $rb;
 
1001
}
 
1002
 
1241
1003
function venue_show($user) {
1242
1004
    $venue = $user->venue;
1243
1005
    if ($venue =='') $venue = '---';
1244
 
    row2("Default computer location", $venue);
 
1006
    row2(tra("Default computer location"), $venue);
1245
1007
}
1246
1008
 
1247
1009
function venue_form($user) {
1250
1012
    if ($user->venue == 'home') $h = 'selected';
1251
1013
    if ($user->venue == 'work') $w = 'selected';
1252
1014
    if ($user->venue == 'school') $s = 'selected';
1253
 
    row2('Default computer location',
 
1015
    row2(tra("Default computer location"),
1254
1016
        "<select name=default_venue>
1255
1017
        <option value=\"\" $n>---
1256
 
        <option value=home $h>Home
1257
 
        <option value=work $w>Work
1258
 
        <option value=school $s>School
 
1018
        <option value=home $h>".tra("Home")."
 
1019
        <option value=work $w>".tra("Work")."
 
1020
        <option value=school $s>".tra("School")."
1259
1021
        </select>"
1260
1022
    );
1261
1023
}
1275
1037
// returns an object with errorvalues or false in success case
1276
1038
//
1277
1039
function prefs_global_parse_form(&$prefs) {
 
1040
    global $cpu_prefs;
 
1041
    global $disk_prefs;
 
1042
    global $net_prefs;
 
1043
 
1278
1044
    $error = false;
1279
 
    $suspend_while_on_batteries = $_GET["suspend_while_on_batteries"];
1280
 
    $suspend_if_user_active = $_GET["suspend_if_user_active"];
1281
 
    $idle_time_to_run = $_GET["idle_time_to_run"];
1282
 
    $suspend_if_no_recent_input = $_GET["suspend_if_no_recent_input"];
1283
 
    $start_hour = $_GET["start_hour"];
1284
 
    $end_hour = $_GET["end_hour"];
1285
 
    $leave_apps_in_memory = $_GET["leave_apps_in_memory"];
1286
 
    $cpu_scheduling_period_minutes = $_GET["cpu_scheduling_period_minutes"];
1287
 
    $max_cpus = $_GET["max_cpus"];
1288
 
    $max_ncpus_pct = $_GET["max_ncpus_pct"];
1289
 
    $cpu_usage_limit = $_GET["cpu_usage_limit"];
1290
 
    $disk_max_used_gb = $_GET["disk_max_used_gb"];
1291
 
    $disk_min_free_gb = $_GET["disk_min_free_gb"];
1292
 
    $disk_max_used_pct = $_GET["disk_max_used_pct"];
1293
 
    $disk_interval = $_GET["disk_interval"];
1294
 
    $vm_max_used_pct = $_GET["vm_max_used_pct"];
1295
 
    $ram_max_used_busy_pct = $_GET["ram_max_used_busy_pct"];
1296
 
    $ram_max_used_idle_pct = $_GET["ram_max_used_idle_pct"];
1297
 
    $work_buf_min_days = $_GET["work_buf_min_days"];
1298
 
    $work_buf_additional_days = $_GET["work_buf_additional_days"];
1299
 
    $confirm_before_connecting = $_GET["confirm_before_connecting"];
1300
 
    $hangup_if_dialed = $_GET["hangup_if_dialed"];
1301
 
    $max_bytes_sec_down = $_GET["max_bytes_sec_down"];
1302
 
    $max_bytes_sec_up = $_GET["max_bytes_sec_up"];
1303
 
    $net_start_hour = $_GET["net_start_hour"];
1304
 
    $net_end_hour = $_GET["net_end_hour"];
1305
 
    $dont_verify_images = $_GET["dont_verify_images"];
1306
 
    // Verification of all user input values
1307
 
    if (!verify_numeric($idle_time_to_run, 1)) $error->idle_time_to_run = true;
1308
 
    if (!verify_numeric($suspend_if_no_recent_input, 0)) $error->suspend_if_no_recent_input = true;
1309
 
    if (!verify_numeric($start_hour, 0)) $error->start_hour = true;
1310
 
    if (!verify_numeric($end_hour, 0)) $error->end_hour = true;
1311
 
    if (!verify_numeric($cpu_scheduling_period_minutes, 1)) $error->cpu_scheduling_period_minutes = true;;
1312
 
    if (!verify_numeric($max_cpus, 0)) $error->max_cpus = true;
1313
 
    if (!verify_numeric($max_ncpus_pct, 0, 100)) $error->max_ncpus_pct = true;
1314
 
    if (!verify_numeric($cpu_usage_limit, 0, 100)) $error->cpu_usage_limit = true;
1315
 
    if (!verify_numeric($disk_max_used_gb, 0)) $error->disk_max_used_gb = true;
1316
 
    if (!verify_numeric($disk_min_free_gb, 0.001)) $error->disk_min_free_gb = true;
1317
 
    if (!verify_numeric($disk_max_used_pct, 0, 100)) $error->disk_max_used_pct = true;
1318
 
    if (!verify_numeric($disk_interval, 0)) $error->disk_interval = true;
1319
 
    if (!verify_numeric($vm_max_used_pct, 0, 100)) $error->vm_max_used_pct = true;
1320
 
    if (!verify_numeric($ram_max_used_busy_pct, 0, 100)) $error->ram_max_used_busy_pct = true;
1321
 
    if (!verify_numeric($ram_max_used_idle_pct, 0, 100)) $error->ram_max_used_idle_pct = true;
1322
 
    if (!verify_numeric($work_buf_min_days, 0, 10)) $error->work_buf_min_days = true;
1323
 
    if (!verify_numeric($work_buf_additional_days, 0, 10)) $error->work_buf_additional_days = true;
1324
 
    if (!verify_numeric($max_bytes_sec_down, '')) $error->max_bytes_sec_down = true;
1325
 
    if (!verify_numeric($max_bytes_sec_up, '')) $error->max_bytes_sec_up = true;
1326
 
    if (!verify_numeric($net_start_hour, 0)) $error->net_start_hour = true;
1327
 
    if (!verify_numeric($net_end_hour, 0)) $error->net_end_hour = true;
1328
 
    // Modify all values within the supplied Object
1329
 
    $prefs->suspend_while_on_batteries = ($suspend_while_on_batteries == "yes");
1330
 
    $prefs->suspend_if_user_active = ($suspend_if_user_active == "yes");
1331
 
    $prefs->idle_time_to_run = $idle_time_to_run;
1332
 
    $prefs->suspend_if_no_recent_input = $suspend_if_no_recent_input;
1333
 
    $prefs->start_hour = $start_hour;
1334
 
    $prefs->end_hour = $end_hour;
1335
 
    $prefs->leave_apps_in_memory = ($leave_apps_in_memory == "yes");
1336
 
    $prefs->cpu_scheduling_period_minutes = $cpu_scheduling_period_minutes;
1337
 
    $prefs->max_cpus = $max_cpus;
1338
 
    $prefs->max_ncpus_pct = $max_ncpus_pct;
1339
 
    $prefs->cpu_usage_limit = $cpu_usage_limit;
1340
 
    $prefs->disk_max_used_gb = $disk_max_used_gb;
1341
 
    $prefs->disk_min_free_gb = $disk_min_free_gb;
1342
 
    $prefs->disk_max_used_pct = $disk_max_used_pct;
1343
 
    $prefs->disk_interval = $disk_interval;
1344
 
    $prefs->vm_max_used_pct = $vm_max_used_pct;
1345
 
    $prefs->ram_max_used_busy_pct = $ram_max_used_busy_pct;
1346
 
    $prefs->ram_max_used_idle_pct = $ram_max_used_idle_pct;
1347
 
    $prefs->work_buf_min_days = $work_buf_min_days;
1348
 
    $prefs->work_buf_additional_days = $work_buf_additional_days;
1349
 
    $prefs->confirm_before_connecting = ($confirm_before_connecting == "yes");
1350
 
    $prefs->hangup_if_dialed = ($hangup_if_dialed == "yes");
1351
 
    $prefs->max_bytes_sec_down = max_bytes_db_mode($max_bytes_sec_down);
1352
 
    $prefs->max_bytes_sec_up = max_bytes_db_mode($max_bytes_sec_up);
1353
 
    $prefs->net_start_hour = $net_start_hour;
1354
 
    $prefs->net_end_hour = $net_end_hour;
1355
 
    $prefs->dont_verify_images = ($dont_verify_images == "yes");
1356
 
 
 
1045
    foreach ($cpu_prefs as $p) {
 
1046
        $p->parse_form($prefs, $error);
 
1047
    }
 
1048
    foreach ($disk_prefs as $p) {
 
1049
        $p->parse_form($prefs, $error);
 
1050
    }
 
1051
    foreach ($net_prefs as $p) {
 
1052
        $p->parse_form($prefs, $error);
 
1053
    }
1357
1054
    return $error;
1358
1055
}
1359
1056
 
1360
 
// This functions parses and verifies the resource value
1361
 
// @param object &$prefs reference to object that stores prefs
1362
 
// @return object an object with errorvalues or false in success case
1363
1057
function prefs_resource_parse_form(&$prefs) {
 
1058
    global $project_pref_descs;
1364
1059
    $error = false;
1365
 
    $resource_share = $_GET['resource_share'];
1366
 
    if (!verify_numeric($resource_share, 0)) $error->resource_share = true;
1367
 
    $prefs->resource_share = $resource_share;
1368
 
 
 
1060
    foreach ($project_pref_descs as $p) {
 
1061
        $p->parse_form($prefs, $error);
 
1062
    }
1369
1063
    return $error;
1370
1064
}
1371
1065
 
1372
 
function prefs_beta_parse_form(&$prefs) {
1373
 
    $prefs->allow_beta_work = false;
1374
 
    $prefs->allow_beta_work_text = "no";
1375
 
    $x = $_GET['allow_beta_work'];
1376
 
    if ($x) {
1377
 
        $prefs->allow_beta_work = true;
1378
 
        $prefs->allow_beta_work_text = "yes";
1379
 
    }
1380
 
}
1381
 
 
1382
1066
function prefs_privacy_parse_form(&$user) {
1383
 
    $user->send_email = ($_GET['send_email'] == "yes")?1:0;
1384
 
    $user->show_hosts = ($_GET['show_hosts'] == "yes")?1:0;
 
1067
    global $privacy_pref_descs;
 
1068
    $error = false;
 
1069
    foreach ($privacy_pref_descs as $p) {
 
1070
        $p->parse_form($user, $error);
 
1071
    }
 
1072
    return $error;
1385
1073
}
1386
1074
 
1387
 
// This function parses the project specific prefs form.
1388
 
// For details look into project/project_specific_prefs.inc
1389
 
// @param object &$prefs refernce to preference object
1390
 
// @return object an object with errorvalues or false in success case
 
1075
// Parse the project specific prefs form.
 
1076
// For details see project/project_specific_prefs.inc
 
1077
//
1391
1078
function prefs_project_parse_form(&$prefs) {
1392
1079
    $error = false;
1393
1080
    $prefs->project_specific = project_specific_prefs_parse_form($error);
1400
1087
// convert prefs from structure to XML
1401
1088
//
1402
1089
function global_prefs_make_xml($prefs, $primary=true) {
1403
 
    // N.B.: each XML entry must end with \n due to the sloppy parsing by the
1404
 
    // BOINC client!!
 
1090
    global $cpu_prefs;
 
1091
    global $disk_prefs;
 
1092
    global $net_prefs;
 
1093
 
1405
1094
    $xml = "";
1406
1095
    if ($primary) {
1407
1096
        $xml = "<global_preferences>\n";
1408
1097
        $now = time();
1409
1098
        $xml = $xml."<mod_time>$now</mod_time>\n";
1410
1099
    }
1411
 
    if (!$prefs->suspend_while_on_batteries) {
1412
 
        $xml = $xml."<run_on_batteries/>\n";
1413
 
    }
1414
 
    if (!$prefs->suspend_if_user_active) {
1415
 
        $xml = $xml."<run_if_user_active/>\n";
1416
 
    }
1417
 
    $xml = $xml."<idle_time_to_run>$prefs->idle_time_to_run</idle_time_to_run>\n";
1418
 
    $xml = $xml."<suspend_if_no_recent_input>$prefs->suspend_if_no_recent_input</suspend_if_no_recent_input>\n";
1419
 
 
1420
 
    if ($prefs->start_hour != $prefs->end_hour) {
1421
 
        $xml = $xml."<start_hour>$prefs->start_hour</start_hour>\n"
1422
 
            ."<end_hour>$prefs->end_hour</end_hour>\n";
1423
 
    }
1424
 
    if ($prefs->leave_apps_in_memory) {
1425
 
        $xml = $xml."<leave_apps_in_memory/>\n";
1426
 
    }
1427
 
    $xml = $xml."<cpu_scheduling_period_minutes>$prefs->cpu_scheduling_period_minutes</cpu_scheduling_period_minutes>\n";
1428
 
    if ($prefs->confirm_before_connecting) {
1429
 
        $xml = $xml."<confirm_before_connecting/>\n";
1430
 
    }
1431
 
    if ($prefs->hangup_if_dialed) {
1432
 
        $xml = $xml."<hangup_if_dialed/>\n";
1433
 
    }
1434
 
    $xml = $xml
1435
 
        ."<work_buf_min_days>$prefs->work_buf_min_days</work_buf_min_days>\n"
1436
 
        ."<work_buf_additional_days>$prefs->work_buf_additional_days</work_buf_additional_days>\n"
1437
 
        ."<max_cpus>$prefs->max_cpus</max_cpus>\n"
1438
 
        ."<max_ncpus_pct>$prefs->max_ncpus_pct</max_ncpus_pct>\n"
1439
 
        ."<cpu_usage_limit>$prefs->cpu_usage_limit</cpu_usage_limit>\n"
1440
 
        ."<disk_interval>$prefs->disk_interval</disk_interval>\n";
1441
 
    $xml = $xml
1442
 
        ."<disk_max_used_gb>$prefs->disk_max_used_gb</disk_max_used_gb>\n"
1443
 
        ."<disk_max_used_pct>$prefs->disk_max_used_pct</disk_max_used_pct>\n"
1444
 
        ."<disk_min_free_gb>$prefs->disk_min_free_gb</disk_min_free_gb>\n"
1445
 
        ."<vm_max_used_pct>$prefs->vm_max_used_pct</vm_max_used_pct>\n"
1446
 
        ."<ram_max_used_busy_pct>$prefs->ram_max_used_busy_pct</ram_max_used_busy_pct>\n"
1447
 
        ."<ram_max_used_idle_pct>$prefs->ram_max_used_idle_pct</ram_max_used_idle_pct>\n"
1448
 
        ."<max_bytes_sec_down>$prefs->max_bytes_sec_down</max_bytes_sec_down>\n"
1449
 
        ."<max_bytes_sec_up>$prefs->max_bytes_sec_up</max_bytes_sec_up>\n";
1450
 
    if ($prefs->net_start_hour != $prefs->net_end_hour) {
1451
 
        $xml = $xml."<net_start_hour>$prefs->net_start_hour</net_start_hour>\n"
1452
 
            ."<net_end_hour>$prefs->net_end_hour</net_end_hour>\n";
1453
 
    }
1454
 
    if ($prefs->dont_verify_images) {
1455
 
        $xml = $xml."<dont_verify_images/>\n";
1456
 
    }
 
1100
 
 
1101
    foreach ($cpu_prefs as $p) {
 
1102
        $xml .= $p->xml_string($prefs);
 
1103
    }
 
1104
    foreach ($disk_prefs as $p) {
 
1105
        $xml .= $p->xml_string($prefs);
 
1106
    }
 
1107
    foreach ($net_prefs as $p) {
 
1108
        $xml .= $p->xml_string($prefs);
 
1109
    }
 
1110
 
1457
1111
    if (isset($prefs->home)) {
1458
1112
        $xml = $xml."<venue name=\"home\">\n".global_prefs_make_xml($prefs->home, false)."</venue>\n";
1459
1113
    }
1472
1126
// given a prefs structure, return the corresponding XML string
1473
1127
//
1474
1128
function project_prefs_make_xml($prefs, $primary=true) {
 
1129
    global $project_pref_descs;
1475
1130
    $xml = "";
1476
1131
    if ($primary) {
1477
1132
        $xml = "<project_preferences>\n";
1478
1133
    }
1479
 
    if ($prefs->resource_share) {
1480
 
        $xml = $xml
1481
 
            ."<resource_share>$prefs->resource_share</resource_share>\n";
1482
 
    }
1483
 
    if ($prefs->allow_beta_work) {
1484
 
        $xml = $xml . "<allow_beta_work>1</allow_beta_work>\n";
 
1134
    foreach ($project_pref_descs as $p) {
 
1135
        $xml .= $p->xml_string($prefs);
1485
1136
    }
1486
1137
    if ($prefs->project_specific) {
1487
1138
        $x = trim($prefs->project_specific);
1508
1159
// Update user's prefs in database, from a given structure
1509
1160
//
1510
1161
function global_prefs_update(&$user, $prefs) {
1511
 
    $prefs_xml = global_prefs_make_xml($prefs);
 
1162
    $prefs_xml = mysql_real_escape_string(global_prefs_make_xml($prefs));
1512
1163
    $query = "update user set global_prefs='$prefs_xml' where id=$user->id";
1513
1164
    $retval = mysql_query($query);
1514
1165
    if (!$retval) {
1515
 
        echo "Update failed: ".htmlspecialchars($query)."\n";
 
1166
        echo tra("Update failed: ").htmlspecialchars($query)."\n";
1516
1167
        echo mysql_error();
1517
1168
        exit();
1518
1169
    }
1521
1172
}
1522
1173
 
1523
1174
function project_prefs_update(&$user, $prefs) {
1524
 
    $prefs_xml = project_prefs_make_xml($prefs);
1525
 
    $retval = mysql_query("update user set project_prefs='$prefs_xml', send_email=$user->send_email, show_hosts=$user->show_hosts where id=$user->id");
 
1175
    $prefs_xml = mysql_real_escape_string(project_prefs_make_xml($prefs));
 
1176
    $send_email = $user->send_email?1:0;
 
1177
    $show_hosts = $user->show_hosts?1:0;
 
1178
    $query = "update user set project_prefs='$prefs_xml', send_email=$send_email, show_hosts=$show_hosts where id=$user->id";
 
1179
    $retval = mysql_query($query);
1526
1180
    $user->project_prefs = $prefs_xml;
1527
1181
    return $retval;
1528
1182
}