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