Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
AdminController.php
1 <?php
2 
4 {
5 
6  public $defaultAction = 'reports';
7 
8  public function actionReports($form_id = null, $csv = false)
9  {
10 
11 
12  $model = new FGForms('search');
13  $form = isset($form_id)? FGForms::model()->findByPk($form_id) : null;
14 
15 
16  if($csv) {
17 
18  return $this->exportCSV($form);
19  }
20 
21  $this->render('reports', array(
22  'forms'=>$model,
23  'currentForm'=>$form
24  ));
25 
26  }
27 
28  public function exportCSV($form)
29  {
30 
31 
32  if(count($form->formdata))
33  {
34 
35  // construct data array
36  $csv = array();
37  // push columns names
38  $csv[0] = array('');
39  foreach(array_keys($form->formdata[0]->getDisplayData()) as $name) {
40  $csv[0][] = $form->getElementLabel($name);
41  }
42  foreach($form->formdata as $fd) {
43  $csv[] = array_merge(array($fd->created_at), array_values($fd->getDisplayData()));
44  }
45 
46  // print csv output
47  Yii::import('application.modules.fg.extensions.UrlTransliterate');
48  header('Content-type: text/csv');
49 
50 
51  // UrlTransliterate causes error 500
52  // header('Content-Disposition: attachment; filename="'.UrlTransliterate::cleanString($form->name, '_').'.csv"');
53 
54  $outstream = fopen('php://output', 'w');
55  foreach($csv as $row) {
56  fputcsv($outstream, $row, ',', '"');
57  }
58 
59 
60  exit;
61  }
62  else
63  {
64 
65  throw new CHttpException(404, 'No reports found');
66  }
67 
68  }
69  public function actionGetMyForms($email)
70  {
71  $model = new FGForms('search');
72  $forms = $model->searchAllForUser($email);
73  $ret = "<table><tr><th>Name</th><th>Aktion</th></tr>";
74  foreach($forms->getData() as $form):
75 
76  $ret.="<tr><td>".$form->name."</td><td>";
77  if(count($form->formdata)):
78  $ret.=CHtml::link("Report anzeigen",array(Yii::app()->createUrl('proxy/fg/admin/reports?form_id='.$form->id.'&csv=1'))).'</td>';
79  else:
80  $ret.="<i>keine Reports vorhanden</i></td>";
81  endif;
82  $ret.="</tr>";
83  endforeach;
84  $ret.="</table>";
85  //$this->render('showmyforms',array('forms' => $forms));
86  echo $ret;
87 
88 
89  }
90  public function actionUpdateCreator($form_id = null, $mail = ''){
91  $form = isset($form_id)? FGForms::model()->findByPk($form_id) : null;
92  if($form && $mail != ''){
93  if($form->creator_email == 'NULL' || $form->creator_email == '' || $form->creator_email == null){
94  $form->creator_email = $mail;
95  $form->update();
96  echo "ok";}
97  else echo "no update";
98  }
99  else{
100  echo "error:".$form_id." ".$mail;
101  }
102 
103  }
104  /*
105  Not used ATM
106  public function actionGetAllReports(){
107  $model = new FGForms('search');
108  $this->render('list_reports',array(
109  'forms' => $model
110  ));
111  } */
112 }