~ihris+botswana/ihris-botswana/trunk

« back to all changes in this revision

Viewing changes to modules/BotswanaEstablishment/lib/Botswana_Page_BulkEstablishment.php

  • Committer: Carl Leitner
  • Date: 2011-05-13 11:15:06 UTC
  • Revision ID: litlfred@ibiblio.org-20110513111506-1e9c0vdg2poi33q8
added ability to export budget worksheets for establishment

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    public function __construct( $args,$request_remainder, $get = null,$post = null) {
48
48
        parent::__construct( $args,$request_remainder,$get,$post);
49
49
        $this->button_templates = array(
50
 
            'button_save'=> 'button_save_only.html',
51
 
            'button_save_only'=> 'button_save_only.html',
52
 
            'button_save_return'=>'button_save_only.html',
53
 
            'button_confirm'=> 'button_save_only.html' ,
54
 
            'button_return_only'=> 'button_save_only.html'
 
50
            'button_save'=> 'button_save_export.html',
 
51
            'button_save_only'=> 'button_save_export.html',
 
52
            'button_save_return'=>'button_save_export.html',
 
53
            'button_confirm'=> 'button_save_export.html' ,
 
54
            'button_return_only'=> 'button_save_export.html'
55
55
            );
56
56
    }
57
57
    protected function loadObjects() {
131
131
     */
132
132
    protected function  loadHTMLTemplatesBulk() {
133
133
        $this->template->addHeaderLink('mootools-core.js');
134
 
 
135
 
        return $this->loadBulk(true);
 
134
        $output = 'html';
 
135
        if ($this->request_exists( 'submit_type' ) && $this->request('submit_type') == "export") {
 
136
            $output = 'csv';
 
137
        }
 
138
        return $this->loadBulk($output);
136
139
    }
137
140
 
138
141
 
140
143
     *get all the establishments for the specified period and get all the posts.
141
144
     * make sure that is an establishment period for each post
142
145
     */
143
 
    protected function  loadBulk($do_templates) {
144
 
        if ($do_templates) {
 
146
    protected function  loadBulk($output = false) {
 
147
        if ($output == 'html') {
145
148
            $this->template->addFile( "bulk_establishment_base.html" );
146
149
            $append_node =  $this->template->getElementByID('establishments');
147
150
            if (!$append_node) {
153
156
                I2CE::raiseError("Could not get line");
154
157
                return false;
155
158
            }
 
159
        } else if ($output == 'csv') {
 
160
            $out = '';
 
161
            $errors = '';
 
162
            while  (ob_get_level() > 0) {
 
163
                $errors .= ob_get_contents();
 
164
                ob_end_clean();
 
165
            }
 
166
            if ($errors) {
 
167
                I2CE::raiseError("Got errors:\n$errors");
 
168
            }
 
169
            $filename = $this->establishment_period->getField('establishment_type')->getDisplayValue() . ' ' . $this->establishment_period->getField('year')->getDisplayValue();
 
170
            header("Content-disposition: attachment; filename=\"$filename\"");
 
171
            if (preg_match('/\s+MSIE\s+\d\.\d;/',$_SERVER['HTTP_USER_AGENT'])) {
 
172
                header("Content-type: application/vnd.ms-excel");
 
173
            } else{
 
174
                header("Content-type: text/csv; charset=UTF-8");  
 
175
            } 
 
176
            flush();             // Flush the headers so the download box appears fast
 
177
            $line = array(
 
178
                'Title of Post',
 
179
                'No. of Posts Requested',
 
180
                'Grade',
 
181
                'Group',
 
182
                'Geographic Location',
 
183
                'Brief Justification',
 
184
                'Notes',
 
185
                'Salary',
 
186
                );
 
187
            foreach ($line as  &$l) {
 
188
                $l = '"' . addslashes($l) . '"';
 
189
            } 
 
190
            unset($l);
 
191
            I2CE::raiseError(implode(",",$line));
 
192
            echo implode(",",$line) . "\n"; flush();            
156
193
        }
157
194
        $no_hidden = array(
158
195
            'operator'=>'OR',
215
252
        $grades =array();
216
253
        $grades_by_name =array();                    
217
254
        foreach ($all_post_ids as $post_id) {
 
255
            $estObj = false;
 
256
            $sgObj = false;
 
257
            $min_salary = 0;
 
258
            $postObj = false;
218
259
            $est_id = array_search($post_id,$post_ids);
219
260
            if ($est_id === false) {
220
261
                if ($do_templates) {
241
282
                $estObj->populate();
242
283
                $estObj->load( $this->post,false,false);                
243
284
            }
244
 
            if ($do_templates) {
245
 
                $e_node = $node->cloneNode(true);
246
 
                $append_node->appendChild($e_node);
247
 
                $this->template->setForm($estObj,$e_node);
 
285
            if ($output) {
 
286
                if ($output == 'html') {
 
287
                    $e_node = $node->cloneNode(true);
 
288
                    $append_node->appendChild($e_node);
 
289
                    $this->template->setForm($estObj,$e_node);
 
290
                }
248
291
                if (!array_key_exists($post_id,$posts)) {
249
292
                    $postObj = $ff->createContainer(array('post', $post_id));
250
293
                    if ($postObj instanceof I2CE_Form) {
256
299
                }            
257
300
                if ($postObj instanceof I2CE_Form) {
258
301
                    $sgObj = false;
259
 
                    $this->template->setForm($postObj,$e_node);
 
302
                    if ($output == 'html') {
 
303
                        $this->template->setForm($postObj,$e_node);
 
304
                    }
260
305
                    if ( ($sgsFields =$postObj->getField('salary_grade')) instanceof I2CE_FormField_MAP_MULT)  {
261
306
                        $grades = $sgsFields->getValue();
262
307
                        $grade = 'salary_grade|' . $grades[1];
324
369
                            }
325
370
                        }
326
371
                    }
327
 
                    $val = 0;
328
372
                        
329
373
                    if ($sgObj instanceof iHRIS_SalaryGrade) {
330
374
                        $sal = $sgObj->getField('start');
331
375
                        if  ($sal instanceof iHRIS_FormField_Currency) {
332
376
                            $sval =  $sal->getValue();
333
377
                            if (is_array($sval)) {
334
 
                                $val = max(0,$sval[1]);
 
378
                                $min_salary = max(0,$sval[1]);
335
379
                            }
336
380
                        }
337
381
                    }
338
 
                    $this->template->setDisplayDataImmediate('salary',$val,$e_node);
 
382
                    if ($output == 'html') {
 
383
                        $this->template->setDisplayDataImmediate('salary',$min_salary,$e_node);
 
384
                    }
339
385
                }
340
386
            }
341
 
            if ($do_templates) {
 
387
            if ($output == 'html') {
342
388
                $this->setObject($estObj,I2CE_PageForm::EDIT_SECONDARY,$e_node);
 
389
            } else if ($output == 'csv') {
 
390
                $line = array();
 
391
                if ($postObj instanceof I2CE_Form) {
 
392
                    $line[0] = $postObj->getField('name')->getDisplayValue() ;
 
393
                    $line[2] = $postObj->getField('salary_grade')->getDisplayValue() ;
 
394
                    $line[3] = $postObj->getField('post_group')->getDisplayValue() ;
 
395
                } else {
 
396
                    $line[0] = '';
 
397
                    $line[2] = '';
 
398
                    $line[3] = '';
 
399
                }
 
400
                if ($estObj instanceof I2CE_Form) {
 
401
                    $line[1] = $estObj->getField('amount')->getDisplayValue();
 
402
                    $line[4] = $estObj->getField('location')->getDisplayValue();
 
403
                    $line[5] = $estObj->getField('justification')->getDisplayValue();
 
404
                    $line[6] = $estObj->getField('notes')->getDisplayValue();
 
405
                } else {
 
406
                    $line[1] = '';
 
407
                    $line[4] = '';
 
408
                    $line[5] = '';
 
409
                    $line[6] = '';
 
410
                }
 
411
                $line[7] = $min_salary;
 
412
                ksort($line);
 
413
                foreach ($line as  &$l) {
 
414
                    $l = '"' . addslashes($l) . '"';
 
415
                } 
 
416
                unset($l);
 
417
                I2CE::raiseError(implode(",",$line));
 
418
                echo implode(",",$line) . "\n"; flush();
343
419
            } else {
344
420
                $this->setObject($estObj,I2CE_PageForm::EDIT_SECONDARY);
345
421
            }
346
422
        }
 
423
        if ($output == 'csv') {
 
424
            exit();
 
425
        }
347
426
        return true;
348
427
        
349
428
    }
373
452
        parent::displayControls($save,$show_edit);
374
453
    }
375
454
 
 
455
 
 
456
 
 
457
    
376
458
    /**
377
459
     * Save the objects to the database.
378
460
     * 
386
468
                return false;
387
469
            }
388
470
        }
 
471
    
389
472
        if ($this->post_exists('redirect')) {
390
473
            $redirect = $this->post('redirect');
391
474
        } else  {
392
475
            $redirect = 'bulkEstablishment?estab_id=' . $this->establishment_period->getNameId() . '&cs_id=' . $this->cs_dept->getNameID();
393
476
        }
394
477
        $this->setRedirect($redirect );
395
 
 
396
478
        return true;
397
479
    }
398
480
 
399
481
 
 
482
 
400
483
    
401
484
 
402
485
}