move code up one directory
[atutor.git] / mods / _standard / basiclti / tool / forms.php
1 <?php
2
3 require_once('../lib/at_form_util.php');
4
5 $blti_instructor_form = array(
6         'title:text:label=bl_title:required=true:size=25',
7         'toolid:id:label=bl_toolid:required=true:size=16',
8         'description:textarea:label=bl_description:required=true:rows=2:cols=25',
9         'toolurl:url:label=bl_toolurl:required=true:size=80',
10         'resourcekey:text:label=bl_resourcekey:required=true:size=80',
11         'password:text:required=true:label=bl_password:size=80',
12         'preferheight:integer:label=bl_preferheight:size=80',
13         'allowpreferheight:radio:label=bl_allowpreferheight:choices=off,on',
14         'launchinpopup:radio:label=bl_launchinpopup:choices=off,on,content',
15         'debuglaunch:radio:label=bl_debuglaunch:choices=off,on,content',
16         'sendname:radio:label=bl_sendname:choices=off,on,content',
17         'sendemailaddr:radio:label=bl_sendemailaddr:choices=off,on,content',
18         'acceptgrades:radio:label=bl_acceptgrades:choices=off,on',
19         'allowroster:radio:label=bl_allowroster:choices=off,on,content',
20         'allowsetting:radio:label=bl_allowsetting:choices=off,on,content',
21     'allowcustomparameters:radio:label=bl_allowcustomparameters:choices=off,on',
22         'customparameters:textarea:label=bl_customparameters:rows=5:cols=25',
23         );
24
25 $blti_admin_form = array();
26 foreach ( $blti_instructor_form as $line ) {
27    $newline = str_replace('choices=off,on,content','choices=off,on,instructor',$line);
28    $blti_admin_form[] = $newline;
29 }
30
31 $blti_admin_form = array_merge($blti_admin_form, array(
32         'organizationid:text:label=bl_organizationid:size=80',
33         'organizationurl:text:label=bl_organizationurl:size=80',
34         'organizationdescr:text:label=bl_organizationdescr:size=80',
35         ) );
36
37 $blti_content_edit_form = array(
38         'preferheight:integer:label=bl_preferheight:size=80',
39         'launchinpopup:radio:label=bl_launchinpopup:choices=off,on',
40         'debuglaunch:radio:label=bl_debuglaunch:choices=off,on',
41         'sendname:radio:label=bl_sendname:choices=off,on',
42         'sendemailaddr:radio:label=bl_sendemailaddr:choices=off,on',
43         'allowroster:radio:label=bl_allowroster:choices=off,on',
44         'allowsetting:radio:label=bl_allowsetting:choices=off,on',
45         'customparameters:textarea:label=bl_customparameters:rows=5:cols=25',
46         );
47
48 if ( ! function_exists('isCli') ) {
49     function isCli() {
50         $sapi_type = php_sapi_name();
51         if (substr($sapi_type, 0, 3) == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
52             return true;
53         } else {
54             return false;
55         }
56     }
57 }
58
59 // If we are running from the command line - do a unit test
60 if ( isCli() ) {
61     function startsWith($haystack,$needle,$case=true) {
62         if($case){return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
63         return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
64     }
65     
66     function endsWith($haystack,$needle,$case=true) {
67         if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
68         return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
69     }
70
71     $i18nstrings = array_merge(foorm_i18n_util($blti_instructor_form), 
72                                foorm_i18n_util($blti_admin_form),
73                                foorm_i18n_util($blti_content_edit_form));
74     $i18nstrings = array_unique($i18nstrings);
75     sort($i18nstrings);
76     foreach ($i18nstrings as $i18n ) {
77          $value = $i18n;
78          if ( startsWith($value,"bl_") ) $value = substr($value,3);
79          if ( endsWith($value,"_on") ) $value = 'Always enabled';
80          if ( endsWith($value,"_off") ) $value = 'Never allowed';
81          if ( endsWith($value,"_instructor") ) $value = 'Delegate to Instructor';
82          if ( endsWith($value,"_content") ) $value = 'Specify in each Content Item';
83          $value = ucfirst($value);
84          
85          echo("INSERT INTO 'language_text' VALUES ('en', '_module','$i18n','$value',NOW(),'');\n");
86     }
87 }
88 ?>