~intrahealth+informatics/ihris-retention/trunk

« back to all changes in this revision

Viewing changes to tools/gen.php

  • Committer: Carl Leitner
  • Date: 2011-04-28 18:44:26 UTC
  • Revision ID: litlfred@ibiblio.org-20110428184426-s1h3evldbyngi6t7
got basic summary reporting working and improved some flow issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
$forms = array(
 
4
    'intervention_A1_develop_recruitment',
 
5
    'intervention_A1_edu_support',
 
6
    'intervention_A1_management',
 
7
    'intervention_A1_other',
 
8
    'intervention_A1_recruit',
 
9
    'intervention_A1_stipend',
 
10
    'intervention_A2_construct',
 
11
    'intervention_A2_furnish_dorms',
 
12
    'intervention_A2_furnish_health_facility',
 
13
    'intervention_A2_furnish_school',
 
14
    'intervention_A2_maintenance',
 
15
    'intervention_A2_management',
 
16
    'intervention_A2_other',
 
17
    'intervention_A3_design_plan',
 
18
    'intervention_A3_management',
 
19
    'intervention_A3_other',
 
20
    'intervention_A3_student_support',
 
21
    'intervention_A3_training',
 
22
    'intervention_A4_develop_curricula',
 
23
    'intervention_A4_dissemination',
 
24
    'intervention_A4_edu_materials',
 
25
    'intervention_A4_other',
 
26
    'intervention_A5_new_edu_program',
 
27
    'intervention_A5_other',
 
28
    'intervention_A5_support_hws',
 
29
    'intervention_A5_training_delivery',
 
30
    'intervention_B1_design_scope',
 
31
    'intervention_B1_other',
 
32
    'intervention_B1_prepare_training',
 
33
    'intervention_B1_training_delivery',
 
34
    'intervention_B1_training_supervisors',
 
35
    'intervention_B2_conduct',
 
36
    'intervention_B2_consult',
 
37
    'intervention_B2_design',
 
38
    'intervention_B2_develop',
 
39
    'intervention_B2_other',
 
40
    'intervention_B2_supervisor',
 
41
    'intervention_B2_support',
 
42
    'intervention_B3_compliance',
 
43
    'intervention_B3_cump',
 
44
    'intervention_B3_management',
 
45
    'intervention_B3_other',
 
46
    'intervention_B3_relocation',
 
47
    'intervention_B3_support',
 
48
    'intervention_B3_train',
 
49
    'intervention_B4_compliance',
 
50
    'intervention_B4_design',
 
51
    'intervention_B4_management',
 
52
    'intervention_B4_other',
 
53
    'intervention_B4_tuition',
 
54
    'intervention_C1_consultations',
 
55
    'intervention_C1_financial_incentives',
 
56
    'intervention_C1_other',
 
57
    'intervention_D1_electric',
 
58
    'intervention_D1_housing',
 
59
    'intervention_D1_other',
 
60
    'intervention_D1_repair',
 
61
    'intervention_D1_school',
 
62
    'intervention_D1_telecomm',
 
63
    'intervention_D1_water',
 
64
    'intervention_D2_medicine',
 
65
    'intervention_D2_other',
 
66
    'intervention_D2_repair',
 
67
    'intervention_D2_routine',
 
68
    'intervention_D2_support',
 
69
    'intervention_D2_train',
 
70
    'intervention_D2_upgrade',
 
71
    'intervention_D3_grants',
 
72
    'intervention_D3_management',
 
73
    'intervention_D3_other',
 
74
    'intervention_D3_outreach_support',
 
75
    'intervention_D3_rural',
 
76
    'intervention_D4_conduct',
 
77
    'intervention_D4_consult',
 
78
    'intervention_D4_design',
 
79
    'intervention_D4_other',
 
80
    'intervention_D4_training',
 
81
    'intervention_D5_conference',
 
82
    'intervention_D5_journal',
 
83
    'intervention_D5_networking',
 
84
    'intervention_D5_other',
 
85
    'intervention_D6_conference',
 
86
    'intervention_D6_design',
 
87
    'intervention_D6_dis_awards',
 
88
    'intervention_D6_health_days',
 
89
    'intervention_D6_nat_awards',
 
90
    'intervention_D6_other'
 
91
    );
 
92
 
 
93
 
 
94
 
 
95
$black = "\033[0m";
 
96
$red = "\033[31m";
 
97
 
 
98
function simple_prompt ($message, $show = null) {
 
99
    global $red,$black;
 
100
    if ($show != null) {
 
101
        $show_message = "/{$red}S{$black}how";
 
102
    } else {
 
103
        $show_message = '';
 
104
    }
 
105
    
 
106
    $message = trim($message)  . "\n({$red}Y{$black}es/{$red}N{$black}o$show_message): ";
 
107
    echo $message;
 
108
    $success =false;
 
109
    while (true) {
 
110
        $c = strtolower(fread(STDIN,1));
 
111
        if ($c=== false) {
 
112
            echo ("Bad input");
 
113
            die();
 
114
        }
 
115
        switch ($c) {
 
116
        case 's':
 
117
            if ($show != null) {
 
118
                echo $show . "\n" . $message;
 
119
            }
 
120
            break;
 
121
        case 'y':
 
122
            return true;
 
123
        case 'n':
 
124
            return false;
 
125
        default:
 
126
            break;
 
127
        }
 
128
    }
 
129
    echo "\n";
 
130
}
 
131
function prompt ($message,&$universal, $show=null) {
 
132
    global $red,$black;
 
133
    if ($universal === true) {
 
134
        return true;
 
135
    }
 
136
    if ($universal === false) {
 
137
        return false;
 
138
    }
 
139
    $message = trim($message);
 
140
    if ($show) {
 
141
        echo "$message\n({$red}Y{$black}es/{$red}N{$black}o/{$red}A{$black}lways/ne{$red}V{$black}er/{$red}S{$black}how): ";
 
142
    } else {
 
143
        echo "$message\n({$red}Y{$black}es/{$red}N{$black}o/{$red}A{$black}lways/ne{$red}V{$black}er): ";
 
144
    }
 
145
    $success =false;
 
146
    while (true) {
 
147
        $c = strtolower(fread(STDIN,1));
 
148
        if ($c=== false) {
 
149
            echo ("Bad input");
 
150
            die();
 
151
        }
 
152
        switch ($c) {
 
153
        case 'y':
 
154
            return true;
 
155
        case 'n':
 
156
            return false;
 
157
        case 'a':
 
158
            $universal = true;
 
159
            return true;
 
160
        case 'v':
 
161
            $universal = false;
 
162
            return false;
 
163
        case 's':
 
164
            if ($show) {
 
165
                echo "\n" . $show . "\n";
 
166
                echo "$message\n({$red}Y{$black}es/{$red}N{$black}o/{$red}A{$black}lways/ne{$red}V{$black}er): ";
 
167
                $show =false;
 
168
            }
 
169
            break;            
 
170
        default:
 
171
            break;
 
172
        }
 
173
    }
 
174
    echo "\n";
 
175
}
 
176
 
 
177
 
 
178
 
 
179
$template = '
 
180
<div>
 
181
  <div class="editRecord">
 
182
    <p>&nbsp;</p>
 
183
    <ul>
 
184
      <li role="planner"><span type="form" name="{{FORM}}:id" href="{{PAGE}}?redirect=view&id=" >Edit this Information</span></li>
 
185
      <li><span href="{{PAGE}}?toggle&amp;id=" type="form" name="{{FORM}}:id" >Enable/Disable</span></li>
 
186
 
 
187
    </ul>
 
188
  </div> <!-- editRecord -->
 
189
  <div class="dataTable">
 
190
    <table border="0" cellspacing="0" cellpadding="0">
 
191
        <tr>
 
192
          <th colspan="2">{{ACTIVITY}}</th>
 
193
        </tr>
 
194
        <tr>
 
195
          <td>
 
196
           <span type="form" name="{{FORM}}:pool" showhead="default" ></span>
 
197
           <span type="form" name="{{FORM}}:enabled" showhead="default" ></span>
 
198
          </td>
 
199
          <tr>
 
200
    </table>
 
201
  </div> <!-- dataTable -->
 
202
 
 
203
  <br style="clear: both;" />
 
204
 
 
205
</div>';
 
206
 
 
207
 
 
208
 
 
209
$skip = null;
 
210
foreach ($forms as $form ) {
 
211
    $in =  $form . '.html';
 
212
    $out = 'view_' . $form . '.html';
 
213
    if (!file_exists($in)) {
 
214
        echo "Could not find $in\n";
 
215
    }
 
216
    if (file_exists($out) && prompt("Skip generating $out as it already exists?",$skip)) {
 
217
        continue;
 
218
    }
 
219
    $src = file_get_contents($in);
 
220
    //<th colspan="2">Activity:Develop rural recruitment plan <span title="Input any activity costs to be paid during the duration of implementing the intervention; recurrent costs" class="fieldhelp">(?)</span></th>
 
221
    $matches = null;
 
222
    if (! preg_match('/Activity\s*:\s*(.*?)</',$src,$matches)) {
 
223
        echo "No activity found in $in\n";
 
224
        continue;
 
225
    }
 
226
    $activity = $matches[1];
 
227
    $matches = null;
 
228
    if (! preg_match('/<h2>(.*?)<\\/h2>/',$src,$matches)) {
 
229
        echo "No intervention found in $in\n";
 
230
        continue;
 
231
    }
 
232
    $intervention = $matches[1];
 
233
    
 
234
    //page: interventionA1develop_recruitment
 
235
    $page = 
 
236
    $html = $template;
 
237
    $replacements = array(
 
238
        'FORM' => $form,
 
239
        'PAGE'=>preg_replace('/_/','',$form, 2),
 
240
        'ACTIVITY'=>$intervention . ' - <i>' . $activity . '</i>'
 
241
        );
 
242
        
 
243
 
 
244
    foreach ($replacements as $key=>$val) {
 
245
        $html = preg_replace('/{{' . $key . '}}/',$val,$html);
 
246
    }
 
247
    file_put_contents($out, $html);
 
248
    
 
249
}
 
 
b'\\ No newline at end of file'