made a copy
[atutor.git] / include / html / course_properties.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
9 /* This program is free software. You can redistribute it and/or                */
10 /* modify it under the terms of the GNU General Public License                  */
11 /* as published by the Free Software Foundation.                                                */
12 /************************************************************************/
13 // $Id$
14 if (!defined('AT_INCLUDE_PATH')) { exit; }
15
16 require_once(AT_INCLUDE_PATH.'lib/filemanager.inc.php');
17 require_once(AT_INCLUDE_PATH.'lib/admin_categories.inc.php');
18 require_once(AT_INCLUDE_PATH.'lib/tinymce.inc.php');
19 //require_once(AT_INCLUDE_PATH.'lib/course_icon.inc.php');
20
21 $_GET['show_courses'] = $addslashes(intval($_GET['show_courses']));
22 $_GET['current_cat'] = $addslashes(intval($_GET['current_cat']));
23
24 if (!isset($_REQUEST['setvisual']) && !isset($_REQUEST['settext'])) {
25         if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 1) {
26                 $_POST['formatting'] = 1;
27                 $_REQUEST['settext'] = 0;
28                 $_REQUEST['setvisual'] = 0;
29
30         } else if ($_SESSION['prefs']['PREF_CONTENT_EDITOR'] == 2) {
31                 $_POST['formatting'] = 1;
32                 $_POST['settext'] = 0;
33                 $_POST['setvisual'] = 1;
34
35         } else { // else if == 0
36                 $_POST['formatting'] = 0;
37                 $_REQUEST['settext'] = 0;
38                 $_REQUEST['setvisual'] = 0;
39         }
40 }
41
42 if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']) {
43         load_editor('banner');
44 }
45
46 if (!isset($isadmin, $course, $db)) {
47         return; 
48 }
49
50 if (isset($_POST['form_course'])) {
51
52         $row['course_id']                       = $_POST['course'];
53         $row['title']                           = $_POST['title'];
54         $row['primary_language']        = $_POST['primary_language'];
55         $row['member_id']                       = $_POST['member_id'];
56         $row['description']                     = $_POST['description'];
57         $row['course_dir_name']         = $_POST['course_dir_name'];
58         $row['cat_id']                          = $_POST['cat_id'];
59         $row['content_packaging']       = $_POST['content_packaging'];
60
61         $row['access']                          = $_POST['access'];
62         $row['notify']                          = $_POST['notify'];
63
64         $row['max_quota']                       = $_POST['max_quota'];
65         $row['max_file_size']           = $_POST['max_file_size'];
66
67         $row['created_date']            = date('Y-m-d H:i:s');
68         $row['primary_language']    = $_POST['pri_lang'];
69         $row['rss']                 = $_POST['rss'];
70
71         $row['copyright']                       = $_POST['copyright'];
72         $row['icon']                            = $_POST['icon'];
73         $row['banner']              = stripcslashes($_POST['banner']);
74
75         if (intval($_POST['release_date'])) {
76                 $day_release    = intval($_POST['day_release']);
77                 $month_release  = intval($_POST['month_release']);
78                 $year_release   = intval($_POST['year_release']);
79                 $hour_release   = intval($_POST['hour_release']);
80                 $min_release    = intval($_POST['min_release']);
81
82                 if (strlen($month_release) == 1){
83                         $month_release = "0$month_release";
84                 }
85                 if (strlen($day_release) == 1){
86                         $day_release = "0$day_release";
87                 }
88                 if (strlen($hour_release) == 1){
89                         $hour_release = "0$hour_release";
90                 }
91                 if (strlen($min_release) == 1){
92                         $min_release = "0$min_release";
93                 }
94                 $row['release_date'] = "$year_release-$month_release-$day_release $hour_release:$min_release:00";
95         } else {
96                 $row['release_date'] = 0;
97         }
98
99         if (intval($_POST['end_date'])) {
100                 $day_end        = intval($_POST['day_end']);
101                 $month_end      = intval($_POST['month_end']);
102                 $year_end       = intval($_POST['year_end']);
103                 $hour_end       = intval($_POST['hour_end']);
104                 $min_end        = intval($_POST['min_end']);
105
106                 if (strlen($month_end) == 1){
107                         $month_end = "0$month_end";
108                 }
109                 if (strlen($day_end) == 1){
110                         $day_end = "0$day_end";
111                 }
112                 if (strlen($hour_end) == 1){
113                         $hour_end = "0$hour_end";
114                 }
115                 if (strlen($min_end) == 1){
116                         $min_end = "0$min_end";
117                 }
118                 $row['end_date'] = "$year_end-$month_end-$day_end $hour_end:$min_end:00";
119         } else {
120                 $row['end_date'] = 0;
121         }
122
123 } else if ($course) {
124         $sql    = "SELECT *, DATE_FORMAT(release_date, '%Y-%m-%d %H:%i:00') AS release_date, DATE_FORMAT(end_date, '%Y-%m-%d %H:%i:00') AS end_date  FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
125         $result = mysql_query($sql, $db);
126         if (!($row      = mysql_fetch_assoc($result))) {
127                 echo _AT('no_course_found');
128                 return;
129         }
130
131 } else {
132         //new course defaults
133         $row['content_packaging']       = 'top';
134         $row['access']                          = 'protected';
135         $row['notify']                          = '';
136         $row['hide']                            = '';
137
138         $row['max_quota']                       = AT_COURSESIZE_DEFAULT;
139         $row['max_file_size']           = AT_FILESIZE_DEFAULT;
140
141         $row['primary_language']        = $_SESSION['lang'];
142         $row['created_date']            = date('Y-m-d H:i:s');
143         $row['rss']                 = 0; // default to off
144         $row['release_date']            = '0';
145         $row['end_date']            = '0';
146 }
147 /*
148 if (($_POST['setvisual'] || $_POST['settext']) && !$_POST['submit']){
149         $anchor =  "#banner";
150 } */
151
152 ?>
153
154 <form method="post" action="<?php echo $_SERVER['PHP_SELF'];  ?>" name="course_form" enctype="multipart/form-data">
155         <input type="hidden" name="form_course" value="true" />
156         <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_config['prof_pic_max_file_size']; ?>" />
157         <input type="hidden" name="course" value="<?php echo $course; ?>" />
158         <input type="hidden" name="old_access" value="<?php echo $row['access']; ?>" />
159         <input type="hidden" name="created_date" value="<?php echo $row['created_date']; ?>" />
160         <input type="hidden" name="show_courses" value="<?php echo $_GET['show_courses']; ?>" />
161         <input type="hidden" name="current_cat" value="<?php echo $_GET['current_cat']; ?>" />
162         <input type="submit" name="submit" style="display:none;"/>
163
164 <div class="input-form">
165         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('properties'); ?></legend>
166 <?php if ($isadmin): ?>
167         <div class="row">
168                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="inst"><?php echo  _AT('instructor'); ?></label><br />
169                         <?php 
170                         $sql = "SELECT member_id, login FROM ".TABLE_PREFIX."members WHERE status=".AT_STATUS_INSTRUCTOR;
171                         $result = mysql_query($sql, $db);
172                         
173                         if ($instructor_row = mysql_fetch_assoc($result)) {
174                                 echo '<select name="instructor" id="inst">';
175                                 do {
176                                         if ($instructor_row['member_id'] == $row['member_id']) {
177                                                 echo '<option value="'.$instructor_row['member_id'].'" selected="selected">'.$instructor_row['login'].'</option>';
178                                         } else {
179                                                 echo '<option value="'.$instructor_row['member_id'].'">'.$instructor_row['login'].'</option>';
180                                         }
181                                 } while($instructor_row = mysql_fetch_assoc($result));
182                                 echo '</select>';
183                         } else {
184                                 echo '<span id="inst">'._AT('none_found').'</span>';
185                         }
186                         ?>
187         </div>
188 <?php endif; ?>
189
190         <div class="row">
191                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="title"><?php echo _AT('title'); ?></label><br />
192                 <input type="text" id="title" name="title" size="40" value="<?php echo htmlspecialchars($row['title']); ?>" />
193         </div>
194
195         <div class="row">
196                 <label for="pri_lang"><?php  echo _AT('primary_language'); ?></label><br />
197                 <?php $languageManager->printDropdown($row['primary_language'], 'pri_lang', 'pri_lang'); ?>
198         </div>
199
200         <div class="row">
201                 <label for="description"><?php echo _AT('description'); ?></label><br />
202                 <textarea id="description" cols="45" rows="2" name="description"><?php echo $row['description']; ?></textarea>
203         </div>
204
205         <?php if ($_config['course_dir_name']): ?>
206         <div class="row">
207                 <label for="course_dir_name"><?php echo _AT('course_dir_name'); ?></label><br />
208                 <input type="text" id="course_dir_name" name="course_dir_name" size="40" value="<?php echo htmlspecialchars($row['course_dir_name']); ?>" />
209         </div>
210         <?php endif; ?>
211
212         <?php $categories = get_categories(); ?>
213         <?php if (is_array($categories)): ?>
214                 <div class="row">
215                 <label for="cat"><?php echo _AT('category'); ?></label><br />
216                         <select name="category_parent" id="cat">
217                                 <option value="0">&nbsp;&nbsp;&nbsp;[&nbsp;&nbsp;<?php echo _AT('cats_uncategorized'); ?>&nbsp;&nbsp;]&nbsp;&nbsp;&nbsp;</option>
218                                 <?php select_categories($categories, 0, $row['cat_id'], false); ?>
219
220                         </select>
221                 </div>
222         <?php endif; ?>
223
224         <div class="row">
225                 <?php  echo _AT('export_content'); ?><br />
226                 <?php
227                         switch ($row['content_packaging']) {
228                                 case 'none':
229                                                 $none = ' checked="checked"';
230                                                 break;
231
232                                 case 'top':
233                                                 $top     = ' checked="checked"';
234                                                 break;
235
236                                 case 'all':
237                                                 $all    = ' checked="checked"';
238                                                 break;
239                         }
240                         ?>
241                 <label><input type="radio" name="content_packaging" value="none" id="none" <?php echo $none; ?> /><?php echo _AT('content_packaging_none'); ?></label><br />
242                 <label><input type="radio" name="content_packaging" value="top" id="ctop"  <?php echo $top; ?> /><?php  echo _AT('content_packaging_top'); ?></label><br />
243                 <label><input type="radio" name="content_packaging" value="all" id="all" <?php echo $all; ?> /><?php  echo _AT('content_packaging_all'); ?></label>
244         </div>
245
246         <div class="row">
247                 <?php echo _AT('syndicate_announcements'); ?><br />
248                 <?php
249                                 $rss_no = $rss_yes = '';
250
251                                 if ($row['rss']) {
252                                         $rss_yes = ' checked="checked"';
253                                 } else {
254                                         $rss_no = ' checked="checked"';
255                                 }
256                 ?>
257                 <label><input type="radio" name="rss" value="1" id="rss_y" <?php echo $rss_yes; ?> /><?php echo _AT('enable_syndicate'); ?></label><br />
258                 <label><input type="radio" name="rss" value="0" id="rss_n"  <?php echo $rss_no; ?> /><?php  echo _AT('disable_syndicate'); ?></label>
259         </div>
260
261         <div class="row">
262                 <?php echo _AT('access'); ?><br />
263                 <?php
264                                 switch ($row['access']) {
265                                         case 'public':
266                                                         $pub = ' checked="checked"';
267                                                         $disable = 'disabled="disabled"'; // disable the nofity box
268                                                         break;
269
270                                         case 'protected':
271                                                         $prot    = ' checked="checked"';
272                                                         $disable = 'disabled="disabled"'; // disable the nofity box
273                                                         break;
274
275                                         case 'private':
276                                                         $priv   = ' checked="checked"';
277                                                         break;
278                                 }
279
280                                 if ($row['notify']) {
281                                         $notify = ' checked="checked"';
282                                 }
283
284                                 if ($row['hide']) {
285                                         $hide = ' checked="checked"';
286                                 }
287                 ?>
288                 <input type="radio" name="access" value="public" id="pub" onclick="disableNotify();" <?php echo $pub; ?> /><label for="pub"><strong> <?php echo  _AT('public'); ?>: </strong></label><?php echo  _AT('about_public'); ?><br /><br />
289
290                 <input type="radio" name="access" value="protected" id="prot" onclick="disableNotify();" <?php echo $prot; ?> /><label for="prot"><strong><?php echo  _AT('protected'); ?>:</strong></label> <?php echo _AT('about_protected'); ?><br /><br />
291
292                 <input type="radio" name="access" value="private" id="priv" onclick="enableNotify();" <?php echo $priv; ?> /><label for="priv"><strong><?php echo  _AT('private'); ?>:</strong></label> <?php echo  _AT('about_private'); ?><br />
293                 <input type="checkbox" name="notify" id="notify" value="1" <?php
294                         echo $disable;
295                         echo $notify; ?> /><label for="notify"><?php echo  _AT('email_approvals'); ?></label>
296                 <br />
297                 <input type="checkbox" name="hide" id="hide" value="1" <?php
298                 echo $disable;
299                 echo $hide; ?> /><label for="hide"><?php echo  _AT('hide_course'); ?></label>.
300         </div>
301
302         <div class="row">
303                 <?php echo _AT('release_date'); ?><br />
304                 <?php
305                         $rel_no = $rel_yes = '';
306
307                         if (intval($row['release_date'])) {
308                                 $rel_yes = ' checked="checked"';
309
310                                 $today_day   = substr($row['release_date'], 8, 2);
311                                 $today_mon   = substr($row['release_date'], 5, 2);
312                                 $today_year  = substr($row['release_date'], 0, 4);
313
314                                 $today_hour  = substr($row['release_date'], 11, 2);
315                                 $today_min   = substr($row['release_date'], 14, 2);
316                         } else {
317                                 $rel_no = ' checked="checked"'; 
318                                 $today_year  = date('Y');
319                         }
320
321                 ?>
322
323                 <input type="radio" name="release_date" value="0" id="release_now" <?php echo $rel_no; ?> /> <label for="release_now"><?php echo _AT('available_immediately'); ?></label><br />
324
325
326                 <input type="radio" name="release_date" value="1" id="release_later" <?php echo $rel_yes; ?> /> <label for="release_later"><?php echo _AT('release_on'); ?></label> 
327                 <?php
328                         $name = '_release';
329                         require(AT_INCLUDE_PATH.'html/release_date.inc.php');
330                 ?>
331         </div>
332
333         <div class="row">
334                 <?php echo _AT('end_date'); ?><br />
335                 <?php
336                         $end_no = $end_yes = '';
337
338                         if (intval($row['end_date'])) {
339                                 $end_yes = ' checked="checked"';
340
341                                 $today_day   = substr($row['end_date'], 8, 2);
342                                 $today_mon   = substr($row['end_date'], 5, 2);
343                                 $today_year  = substr($row['end_date'], 0, 4);
344
345                                 $today_hour  = substr($row['end_date'], 11, 2);
346                                 $today_min   = substr($row['end_date'], 14, 2);
347                         } else {
348                                 $end_no = ' checked="checked"'; 
349                                 $today_year  = date('Y')+1;
350                         }
351
352                 ?>
353
354                 <input type="radio" name="end_date" value="0" id="end_now" <?php echo $end_no; ?> /> <label for="end_now"><?php echo _AT('no_end_date'); ?></label><br />
355
356                 <input type="radio" name="end_date" value="1" id="end_later" <?php echo $end_yes; ?> /> <label for="end_later"><?php echo _AT('end_on'); ?></label> 
357                 <?php
358                         $name = '_end';
359                         require(AT_INCLUDE_PATH.'html/release_date.inc.php');
360                 ?>
361         </div>
362
363         <div class="row">
364                 <?php
365                         if (($_POST['setvisual'] && !$_POST['settext']) || $_GET['setvisual']){
366                                 echo '<input type="hidden" name="setvisual" value="'.$_POST['setvisual'].'" />';
367                                 echo '<input type="submit" name="settext" value="'._AT('switch_text').'" />';
368                         } else {
369                                 echo '<input type="submit" name="setvisual" value="'._AT('switch_visual').'" />';
370                         }
371                 ?>
372         </div>
373         <div class="row">
374
375                 <label for="banner"><?php echo _AT('banner'); ?></label><br />
376                 <textarea id="banner" cols="45" rows="15" name="banner"><?php echo $row['banner']; ?></textarea>
377         </div>
378
379 <?php if (!$course) : ?>
380         <div class="row">
381                 <label for="initial_content"><?php echo _AT('initial_content'); ?></label><br />
382                 <select name="initial_content" id="initial_content" size="5">
383                         <option value="0"><?php echo _AT('empty'); ?></option>
384                         <option value="1" selected="selected"><?php echo _AT('create_basic'); ?></option>
385                         <?php 
386                         $Backup = new Backup($db);
387
388                         if ($isadmin) {
389                                 $sql    = "SELECT course_id, title FROM ".TABLE_PREFIX."courses ORDER BY title";
390                         } else {
391                                 $sql    = "SELECT course_id, title FROM ".TABLE_PREFIX."courses WHERE member_id=$_SESSION[member_id] ORDER BY title";
392                         }
393
394                         $result = mysql_query($sql, $db);
395
396                         if ($course_row = mysql_fetch_assoc($result)) {
397                                 do {
398                                         $Backup->setCourseID($course_row['course_id']);
399                                         $list = $Backup->getAvailableList();
400
401                                         if (!empty($list)) { 
402                                                 echo '<optgroup label="'. _AT('restore').': '.$course_row['title'].'">';
403                                                 foreach ($list as $list_item) {
404                                                         echo '<option value="'.$list_item['backup_id'].'_'.$list_item['course_id'].'">'.$list_item['file_name'].' - '.get_human_size($list_item['file_size']).'</option>';
405                                                 }
406                                                 echo '</optgroup>';
407                                         }
408                                 } while ($course_row = mysql_fetch_assoc($result));
409                         }
410                         ?>
411                         </select>
412         </div>
413 <?php endif; // !$course_id ?>
414
415 <?php if ($isadmin) : ?>
416         <div class="row">
417                 <?php  echo _AT('course_quota'); ?><br />
418                 <?php 
419                         if ($row['max_quota'] == AT_COURSESIZE_UNLIMITED) { 
420                                 $c_unlim = ' checked="checked" ';
421                                 $c_oth2 = ' disabled="disabled" ';
422                         } elseif ($row['max_quota'] == AT_COURSESIZE_DEFAULT) {
423                                 $c_def = ' checked="checked" ';
424                                 $c_oth2 = ' disabled="disabled" ';
425                         } else {
426                                 $c_oth = ' checked="checked" ';
427                                 $c_oth2 = '';
428                         }
429
430                         if ($course > 0) {
431                                 $course_size = dirsize(AT_CONTENT_DIR . $course.'/');
432                         } else {
433                                 $course_size = 0;
434                         }
435
436                         if ($course) {
437                                 echo _AT('current_course_size') .': '.get_human_size($course_size).'<br />'; 
438                         }
439                 ?>
440
441                 <input type="radio" id="c_default" name="quota" value="<?php echo AT_COURSESIZE_DEFAULT; ?>" onclick="disableOther();" <?php echo $c_def;?> /><label for="c_default"> <?php echo _AT('default') . ' ('.get_human_size($MaxCourseSize).')'; ?></label> <br />
442                 <input type="radio" id="c_unlim" name="quota" value="<?php echo AT_COURSESIZE_UNLIMITED; ?>" onclick="disableOther();" <?php echo $c_unlim;?>/><label for="c_unlim"> <?php echo _AT('unlimited'); ?></label> <br />
443                 <input type="radio" id="c_other" name="quota" value="2" onclick="enableOther();" <?php echo $c_oth;?>/><label for="c_other"> <?php echo _AT('other'); ?> </label> - 
444                 <input type="text" id="quota_entered" name="quota_entered" <?php echo $c_oth2?> value="<?php if ($row['max_quota']!=AT_COURSESIZE_UNLIMITED && $row['max_quota']!=AT_COURSESIZE_DEFAULT) { echo bytes_to_megabytes($row['max_quota']); } ?>" size="4" /> <?php echo _AT('mb'); ?>
445         </div>
446
447         <div class="row">
448                 <?php  echo _AT('max_file_size'); ?><br />
449                 <?php 
450                         $max_allowed = megabytes_to_bytes(substr(ini_get('upload_max_filesize'), 0, -1));
451
452                         if ($row['max_file_size'] == AT_FILESIZE_DEFAULT) { 
453                                 $f_def = ' checked="checked" ';
454                                 $f_oth2 = ' disabled="disabled" ';
455                         } elseif ($row['max_file_size'] == AT_FILESIZE_SYSTEM_MAX) {
456                                 $f_max = ' checked="checked" ';
457                                 $f_oth2 = ' disabled="disabled" ';
458                         } else {
459                                 $f_oth = ' checked="checked" ';
460                                 $f_oth2 = '';
461                         }
462                 ?>
463                 <input type="radio" id="f_default" name="filesize" value="<?php echo AT_FILESIZE_DEFAULT; ?>" onclick="disableOther2();" <?php echo $f_def;?> /><label for="f_default"> <?php echo _AT('default') . ' ('.get_human_size($MaxFileSize).')'; ?></label> <br />
464                 <input type="radio" id="f_maxallowed" name="filesize" value="<?php echo AT_FILESIZE_SYSTEM_MAX; ?>" onclick="disableOther2();" <?php echo $f_max;?>/><label for="f_maxallowed"> <?php echo _AT('max_file_size_system') . ' ('.get_human_size($max_allowed).')'; ?></label> <br />
465                 <input type="radio" id="f_other" name="filesize" value="2" onclick="enableOther2();" <?php echo $f_oth;?>/><label for="f_other"> <?php echo _AT('other'); ?> </label> - 
466                 <input type="text" id="filesize_entered" name="filesize_entered" <?php echo $f_oth2?> value="<?php if ($row['max_file_size']!=AT_FILESIZE_DEFAULT && $row['max_file_size']!=AT_FILESIZE_SYSTEM_MAX) { echo bytes_to_megabytes($row['max_file_size']); } ?>" size="4" /> <?php echo _AT('mb'); ?>
467         </div>
468
469 <?php else: ?>
470         <input type="hidden" name="quota" value="<?php echo $row['max_quota']; ?>" />
471         <input type="hidden" name="filesize" value="<?php echo $row['max_file_size']; ?>" />
472         <input type="hidden" name="tracking" value="<?php echo $row['tracking']; ?>" />
473 <?php endif; ?>
474
475         <div class="row">
476                 <label for="copyright"><?php echo _AT('course_copyright'); ?></label><br />
477                 <textarea name="copyright" rows="2" cols="65" id="copyright"><?php echo $row['copyright']; ?></textarea>
478         </div>
479         <div class="row">
480                 <?php 
481             if ($row['icon'] != ''): 
482                 $path = AT_CONTENT_DIR.$row['course_id']."/custom_icons/";
483                 if (file_exists($path.$row['icon'])) {
484                     if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
485                         $_base_href = 'get_course_icon.php/?id='.$row['course_id'];
486                     } else {
487                         $_base_href = 'content/' . $row['course_id'] . '/';
488                     }
489                 } else {
490                     $_base_href = "images/courses/";
491                                             //$_base_href = 'get_course_icon.php/?id='.$row['course_id'];
492                 }
493
494             $force_get = (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) ? true : false;
495             echo "<input type='hidden' name='boolForce' id='boolForce' value='$force_get' />";
496         
497        //include(AT_INCLUDE_PATH.'html/course_icon.inc.php');
498         
499         
500         ?>
501                 <img id="i0" src="<?php echo $_base_href.$row['icon']; ?>" alt="<?php echo $row['icon']; ?>" border="1" height="79" width="79"  style="float: left; margin: 2px;" />
502
503                 <?php else: ?>
504                         <img id="i0" src="images/clr.gif" alt="" style="float: left; margin: 2px;" border="1" height="79" width="79"  />
505                         <input type='hidden' name='boolForce' id='boolForce' value='' />
506                 <?php endif; ?>
507                 <div style="width:40%; float:left;">
508                 <label for="icons"><?php echo _AT('icon'); ?></label><br />
509                 <select name="icon" id="icons" onchange="SelectImg()">
510                         <option value=""><?php echo _AT('no_icon'); ?></option>
511             <?php // ------------- custom course icons
512                 $path = AT_CONTENT_DIR.$row['course_id']."/custom_icons/";
513                 $boolCustom = false;
514                 $optCount = 0;
515
516                 if (is_dir($path)) {
517                     $boolCustom = true;  // true if custom icons are uploaded, otherwise false
518                     
519                     /*$files = scandir($path);  //SCANDIR STOPS ATUTOR WHEN RUN AS INSTRUCTOR, BUT NOT AS ADMIN. WHY? -Gorzan */
520                     
521                     /* PHP 4 REPLACEMENT FOR SCANDIR */
522                                         $dh  = opendir($path);
523                                         while (false !== ($filename = readdir($dh))) {
524                                                 $files[] = $filename;
525                                         }
526
527                                         /*END PHP 4 REPLACEMENT FOR SCANDIR*/
528                     echo "<optgroup label='"._AT('custom_icons')."'>";
529                     foreach($files as $val) {
530                                                 $file_ext = substr(strtolower($val), -3);
531                         if ($file_ext == "jpg" || $file_ext == "png" || $file_ext == "gif") {
532                             $optCount++;
533                             echo "<option value='".$val."'";
534                             if ($val == $row['icon']) {
535                                 echo 'selected="selected"';
536                             }
537                             echo ">".$val."</option>";
538                         }
539                     }
540                     echo "</optgroup>";
541                 }
542                 
543             ?>
544                         <?php // ------------- other icons
545
546                                 $course_imgs = array();
547                                 if ($dir = opendir('../images/courses/')) {
548                                         while (false !== ($file = readdir($dir)) ) {
549                                                 if( ($file == '.') || ($file == '..')) { 
550                                                         continue;
551                                                 }
552                                                 $course_imgs[] = $file;
553                                         }               
554                                         closedir($dir); 
555                                 }
556                                 sort($course_imgs);
557                 if ($boolCustom == true) {
558                     echo "<optgroup label='"._AT('builtin_icons')."'>";
559                 }
560                                 foreach ($course_imgs as $file) {
561                                         echo '<option value="' . $file . '" ';
562                                         if ($file == $row['icon']) { 
563                                                 echo 'selected="selected"'; 
564                                         }
565                                         echo ' >' . $file . '</option>';        
566                                 }
567                 if ($boolCustom == true) {
568                     echo "</optgroup>";
569                 }
570                         ?>
571                 </select><?php echo "&nbsp;&nbsp;&nbsp; "._AT('or'); ?>
572         </div>
573             <!-- div class="row" style="float:right;width:40%;">
574             <?php echo _AT('upload_icon'); ?><br />
575                 <input type="file" name="customicon" id="customicon" value="<?php echo $_POST['customicon']; ?>"/><br />
576                 <small><?php echo _AT('upload_icon_text'); ?></small>
577             </div -->
578
579         <?php  require_once(AT_INCLUDE_PATH.'html/course_icon.inc.php'); ?>
580
581         <br style="clear: left;" />
582
583         </div>
584
585     <div style="clear: both;"></div>
586
587     
588
589         <div class="buttons">
590                 <?php
591             echo "<input type='hidden' name='custOptCount' id='custOptCount' value='".$optCount."' />";
592             echo "<input type='hidden' name='courseId' id='courseId' value='".$row['course_id']."' />";
593                 ?>
594
595                 <input type="submit" name="submit" value="<?php echo _AT('save'); ?>" accesskey="s" /> 
596                 <input type="submit" name="cancel" value="<?php echo _AT('cancel');?>" />
597         </div>
598     </fieldset>
599 </div>
600
601 </form>
602 <?php
603
604 if ($_POST['customicon']) {
605     echo "<script language='javascript' type='text/javascript'>document.getElementById('uploadform').focus();</script>";
606 }
607 ?>
608
609 <script language="javascript" type="text/javascript">
610 <!--
611 function enableNotify() {
612         document.course_form.notify.disabled = false;
613         document.course_form.hide.disabled = false;
614 }
615
616 function disableNotify() {
617         document.course_form.notify.disabled = true;
618         document.course_form.hide.disabled = true;
619 }
620
621 function enableOther()          { document.course_form.quota_entered.disabled = false; }
622 function disableOther()         { document.course_form.quota_entered.disabled = true; }
623 function enableOther2()         { document.course_form.filesize_entered.disabled = false; }
624 function disableOther2()        { document.course_form.filesize_entered.disabled = true; }
625
626 function enableRelease() { 
627         document.course_form.day_release.disabled = false; 
628         document.course_form.month_release.disabled = false; 
629         document.course_form.year_release.disabled = false; 
630         document.course_form.hour_release.disabled = false; 
631         document.course_form.min_release.disabled = false; 
632 }
633 function disableRelease() { 
634         document.course_form.day_release.disabled = true; 
635         document.course_form.month_release.disabled = true; 
636         document.course_form.year_release.disabled = true; 
637         document.course_form.hour_release.disabled = true; 
638         document.course_form.min_release.disabled = true; 
639 }
640
641 function SelectImg() {
642     // UPDATED by Martin Turlej - for custom course icon
643
644     var boolForce = document.getElementById('boolForce').value;
645         if (document.course_form.icon.options[document.course_form.icon.selectedIndex].value == "") {
646                 document.getElementById('i0').src = "images/clr.gif";
647                 document.getElementById('i0').alt = "";
648         } else {
649         var iconIndx = document.course_form.icon.selectedIndex;
650         var custIndx = document.getElementById('custOptCount').value;
651         var courseId = document.getElementById('courseId').value;
652
653         // if icon is part of custom icons choose corresponding directory
654         if (iconIndx <= custIndx && boolForce != '') {                  
655             var dir = (boolForce == 1) ? "get_course_icon.php/?id="+courseId : "/content/"+courseId+"/custom_icons/";
656         } else {
657             var dir = "images/courses/";
658         }
659
660                 document.getElementById('i0').src = dir + document.course_form.icon.options[iconIndx].value;
661                 document.getElementById('i0').alt = document.course_form.icon.options[iconIndx].value;
662         }
663 }
664
665 function toggleFrm(id) {
666     if (document.getElementById(id).style.display == "none") {
667                 //show
668                 document.getElementById(id).style.display='';   
669
670                 if (id == "c_folder") {
671                         document.form0.new_folder_name.focus();
672                 } else if (id == "upload") {
673                         document.form0.file.focus();
674                 }
675
676         } else {
677                 //hide
678                 document.getElementById(id).style.display='none';
679         }
680 }
681 // -->
682 </script>