ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAttendanceList.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
15  protected $parent_obj; // [object]
16  protected $participants; // [object]
17  protected $callback; // [string|array]
18  protected $presets; // [array]
19  protected $show_admins; // [bool]
20  protected $show_tutors; // [bool]
21  protected $show_members; // [bool]
22  protected $blank_columns; // [array]
23  protected $title; // [string]
24  protected $description; // [string]
25  protected $pre_blanks; // [array]
26  protected $id; // [string]
27 
34  function __construct($a_parent_obj, $a_participants_object = null)
35  {
36  global $lng;
37 
38  $this->parent_obj = $a_parent_obj;
39  $this->participants = $a_participants_object;
40 
41  // always available
42  $this->presets['name'] = array($lng->txt('name'), true);
43  $this->presets['login'] = array($lng->txt('login'), true);
44  $this->presets['email'] = array($lng->txt('email'));
45  }
46 
54  function addPreset($a_id, $a_caption, $a_selected = false)
55  {
56  $this->presets[$a_id] = array($a_caption, $a_selected);
57  }
58 
64  function addBlank($a_caption)
65  {
66  $this->pre_blanks[] = $a_caption;
67  }
68 
75  function setTitle($a_title, $a_description = null)
76  {
77  $this->title = $a_title;
78  $this->description = $a_description;
79  }
80 
86  function showAdmins($a_value = true)
87  {
88  $this->show_admins = (bool)$a_value;
89  }
90 
96  function showTutors($a_value = true)
97  {
98  $this->show_tutors = (bool)$a_value;
99  }
100 
106  function showMembers($a_value = true)
107  {
108  $this->show_members = (bool)$a_value;
109  }
110 
116  function setBlankColumns(array $a_values)
117  {
118  if(!implode("", $a_values))
119  {
120  $a_values = array();
121  }
122  else
123  {
124  foreach($a_values as $idx => $value)
125  {
126  $a_values[$idx] = trim($value);
127  if($a_values[$idx] == "")
128  {
129  unset($a_values[$idx]);
130  }
131  }
132  }
133  $this->blank_columns = $a_values;
134  }
135 
141  function setCallback($a_callback)
142  {
143  $this->callback = $a_callback;
144  }
145 
151  function setId($a_value)
152  {
153  $this->id = (string)$a_value;
154  }
155 
162  public function initForm($a_cmd = "")
163  {
164  global $ilCtrl, $lng;
165 
166  $lng->loadLanguageModule('crs');
167 
168  include_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
169  $form = new ilPropertyFormGUI();
170  $form->setFormAction($ilCtrl->getFormAction($this->parent_obj,$a_cmd));
171  $form->setTarget('_blank');
172  $form->setTitle($lng->txt('sess_gen_attendance_list'));
173 
174  $title = new ilTextInputGUI($lng->txt('title'), 'title');
175  $title->setValue($this->title);
176  $form->addItem($title);
177 
178  $desc = new ilTextInputGUI($lng->txt('description'), 'desc');
179  $desc->setValue($this->description);
180  $form->addItem($desc);
181 
182  if(sizeof($this->presets))
183  {
184  $preset = new ilCheckboxGroupInputGUI($lng->txt('user_detail'), 'preset');
185  $preset_value = array();
186  foreach($this->presets as $id => $item)
187  {
188  $preset->addOption(new ilCheckboxOption($item[0], $id));
189  if($item[1])
190  {
191  $preset_value[] = $id;
192  }
193  }
194  $preset->setValue($preset_value);
195  $form->addItem($preset);
196  }
197 
198  $blank = new ilTextInputGUI($lng->txt('event_blank_columns'), 'blank');
199  $blank->setMulti(true);
200  $form->addItem($blank);
201 
202  if($this->pre_blanks)
203  {
204  $blank->setValue($this->pre_blanks);
205  }
206 
207  $part = new ilFormSectionHeaderGUI();
208  $part->setTitle($lng->txt('event_participant_selection'));
209  $form->addItem($part);
210 
211  // Admins
212  $admin = new ilCheckboxInputGUI($lng->txt('event_tbl_admins'),'show_admins');
213  $admin->setOptionTitle($lng->txt('event_inc_admins'));
214  $admin->setValue(1);
215  $form->addItem($admin);
216 
217  // Tutors
218  $tutor = new ilCheckboxInputGUI($lng->txt('event_tbl_tutors'),'show_tutors');
219  $tutor->setOptionTitle($lng->txt('event_inc_tutors'));
220  $tutor->setValue(1);
221  $form->addItem($tutor);
222 
223  // Members
224  $member = new ilCheckboxInputGUI($lng->txt('event_tbl_members'),'show_members');
225  $member->setOptionTitle($lng->txt('event_inc_members'));
226  $member->setValue(1);
227  $member->setChecked(true);
228  $form->addItem($member);
229 
230  $form->addCommandButton($a_cmd,$lng->txt('sess_print_attendance_list'));
231 
232  if($this->id && $a_cmd)
233  {
234  include_once "Services/User/classes/class.ilUserFormSettings.php";
235  $settings = new ilUserFormSettings($this->id);
236  $settings->deleteValue('desc');
237  $settings->exportToForm($form);
238  }
239 
240  return $form;
241  }
242 
246  public function initFromForm()
247  {
248  $form = $this->initForm();
249  if($form->checkInput())
250  {
251  foreach(array_keys($this->presets) as $id)
252  {
253  $this->presets[$id][1] = false;
254  }
255  foreach($form->getInput('preset') as $value)
256  {
257  if(isset($this->presets[$value]))
258  {
259  $this->presets[$value][1] = true;
260  }
261  else
262  {
263  $this->addPreset($value, $value, true);
264  }
265  }
266 
267  $this->setTitle($form->getInput('title'), $form->getInput('desc'));
268  $this->setBlankColumns($form->getInput('blank'));
269  $this->showAdmins($form->getInput('show_admins'));
270  $this->showTutors($form->getInput('show_tutors'));
271  $this->showMembers($form->getInput('show_members'));
272 
273  if($this->id)
274  {
275  $form->setValuesByPost();
276 
277  include_once "Services/User/classes/class.ilUserFormSettings.php";
278  $settings = new ilUserFormSettings($this->id);
279  $settings->deleteValue('desc');
280  $settings->importFromForm($form);
281  $settings->store();
282  }
283 
284  }
285  }
286 
292  public function getFullscreenHTML()
293  {
294  $tpl = new ilTemplate('tpl.main.html',true,true);
295  $tpl->setBodyClass("ilBodyPrint");
296 
297  // load style sheet depending on user's settings
298  $location_stylesheet = ilUtil::getStyleSheetLocation();
299  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
300 
301  $tpl->setVariable("BODY_ATTRIBUTES",'onload="window.print()"');
302  $tpl->setVariable("CONTENT", $this->getHTML());
303 
304  return $tpl->show();
305  }
306 
312  public function getHTML()
313  {
314  $tpl = new ilTemplate('tpl.attendance_list_print.html',true,true,'Services/Membership');
315 
316 
317  // title
318 
319  $time = ilFormat::formatUnixTime(time(),true);
320 
321  $tpl->setVariable('TXT_TITLE', $this->title);
322  if($this->description)
323  {
324  $tpl->setVariable('TXT_DESCRIPTION', $this->description." (".$time.")");
325  }
326  else
327  {
328  $tpl->setVariable('TXT_DESCRIPTION', $time);
329  }
330 
331 
332  // header
333 
334  $tpl->setCurrentBlock('head_item');
335  foreach($this->presets as $id => $item)
336  {
337  if($item[1])
338  {
339  $tpl->setVariable('TXT_HEAD', $item[0]);
340  $tpl->parseCurrentBlock();
341  }
342  }
343 
344  if($this->blank_columns)
345  {
346  foreach($this->blank_columns as $blank)
347  {
348  $tpl->setVariable('TXT_HEAD', $blank);
349  $tpl->parseCurrentBlock();
350  }
351  }
352 
353 
354  // handle members
355 
356  $member_ids = array();
357  if($this->show_admins)
358  {
359  $member_ids = array_merge((array)$member_ids,$this->participants->getAdmins());
360  }
361  if($this->show_tutors)
362  {
363  $member_ids = array_merge((array)$member_ids,$this->participants->getTutors());
364  }
365  if($this->show_members)
366  {
367  $member_ids = array_merge((array)$member_ids,$this->participants->getMembers());
368  }
369  $member_ids = ilUtil::_sortIds((array) $member_ids,'usr_data','lastname','usr_id');
370 
371 
372  // rows
373 
374  foreach($member_ids as $user_id)
375  {
376  if($this->callback)
377  {
378  $user_data = call_user_func_array($this->callback, array($user_id));
379 
380  $tpl->setCurrentBlock("row_preset");
381  foreach($this->presets as $id => $item)
382  {
383  if($item[1])
384  {
385  switch($id)
386  {
387  case "name":
388  if(!$user_data[$id])
389  {
390  $name = ilObjUser::_lookupName($user_id);
391  $value = $name["lastname"].", ".$name["firstname"];
392  break;
393  }
394 
395 
396  case "email":
397  if(!$user_data[$id])
398  {
399  $value = ilObjUser::_lookupEmail($user_id);
400  break;
401  }
402 
403 
404  case "login":
405  if(!$user_data[$id])
406  {
407  $value = ilObjUser::_lookupLogin($user_id);
408  break;
409  }
410 
411  default:
412  $value = (string)$user_data[$id];
413  break;
414  }
415  $tpl->setVariable("TXT_PRESET", $value);
416  $tpl->parseCurrentBlock();
417  }
418  }
419  }
420 
421  if($this->blank_columns)
422  {
423  for($loop = 0; $loop < sizeof($this->blank_columns); $loop++)
424  {
425  $tpl->touchBlock('row_blank');
426  }
427  }
428 
429  $tpl->touchBlock("member_row");
430  }
431 
432  return $tpl->get();
433  }
434 }
435 
436 ?>