fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

tasktypeeditmanagementpage.class.php
Go to the documentation of this file.
1 <?php
23 {
29  public $node = 'tasktypeedit';
37  public function __construct($name = '')
38  {
39  $this->name = 'Task Type Management';
40  self::$foglang['ExportTasktypeedit'] = _('Export Task Types');
41  self::$foglang['ImportTasktypeedit'] = _('Import Task Types');
42  parent::__construct($this->name);
43  $this->menu['list'] = sprintf(self::$foglang['ListAll'], _('Task Types'));
44  $this->menu['add'] = sprintf(self::$foglang['CreateNew'], _('Task Type'));
45  global $id;
46  global $sub;
47  if ($id) {
48  $this->subMenu = array(
49  "$this->linkformat#tasktype-gen" => self::$foglang['General'],
50  $this->delformat => self::$foglang['Delete'],
51  );
52  $this->notes = array(
53  _('Name') => $this->obj->get('name'),
54  _('Icon') => sprintf(
55  '<i class="fa fa-%s"></i>',
56  $this->obj->get('icon')
57  ),
58  _('Type') => $this->obj->get('type'),
59  );
60  }
61  $this->headerData = array(
62  '<input type="checkbox" name="toggle-checkbox" class='
63  . '"toggle-checkboxAction"/>',
64  _('Name'),
65  _('Access'),
66  _('Kernel Args'),
67  );
68  $this->templates = array(
69  '<input type="checkbox" name="tasktypeedit[]" value='
70  . '"${id}" class="toggle-action"/>',
71  sprintf(
72  '<a href="?node=%s&sub=edit&id=${id}" title='
73  . '"Edit"><i class="fa fa-${icon} fa-1x"> ${name}</i></a>',
74  $this->node
75  ),
76  '${access}',
77  '${args}',
78  );
79  $this->attributes = array(
80  array(
81  'width' => 16,
82  'class' => 'filter-false'
83  ),
84  array(),
85  array(),
86  array()
87  );
95  self::$returnData = function (&$TaskType) {
96  $this->data[] = array(
97  'icon' => $TaskType->icon,
98  'id' => $TaskType->id,
99  'name' => $TaskType->name,
100  'access' => $TaskType->access,
101  'args' => $TaskType->kernelArgs,
102  );
103  unset($TaskType);
104  };
105  }
111  public function add()
112  {
113  $this->title = _('New Task Type');
114  unset($this->headerData);
115  $this->attributes = array(
116  array('class' => 'col-xs-4'),
117  array('class' => 'col-xs-8 form-group'),
118  );
119  $this->templates = array(
120  '${field}',
121  '${input}',
122  );
123  $name = filter_input(
124  INPUT_POST,
125  'name'
126  );
127  $description = filter_input(
128  INPUT_POST,
129  'description'
130  );
131  $icon = filter_input(
132  INPUT_POST,
133  'icon'
134  );
135  $kernel = filter_input(
136  INPUT_POST,
137  'kernel'
138  );
139  $kernelargs = filter_input(
140  INPUT_POST,
141  'kernelargs'
142  );
143  $initrd = filter_input(
144  INPUT_POST,
145  'initrd'
146  );
147  $type = filter_input(
148  INPUT_POST,
149  'type'
150  );
151  $access = filter_input(
152  INPUT_POST,
153  'access'
154  );
155  $advanced = isset($_POST['advanced']);
156  $isAd = (
157  $advanced ?
158  ' checked' :
159  ''
160  );
161  $accessTypes = array(
162  'both',
163  'host',
164  'group'
165  );
166  $accessSel = self::selectForm(
167  'access',
168  $accessTypes,
169  $access
170  );
171  unset($accessTypes);
172  $fields = array(
173  '<label for="name">'
174  . _('Name')
175  . '</label>' => '<div class="input-group">'
176  . '<input type="text" name="name" id="name" value="'
177  . $name
178  . '" class="form-control" autocomplete="off" '
179  . 'required/>'
180  . '</div>',
181  '<label for="description">'
182  . _('Description')
183  . '</label>' => '<div class="input-group">'
184  . '<textarea name="description" id="description" class="form-control">'
185  . $description
186  . '</textarea>'
187  . '</div>',
188  '<label for="icon">'
189  . _('Icon')
190  . '</label>' => self::getClass('TaskType')->iconlist($icon),
191  '<label for="kernel">'
192  . _('Kernel')
193  . '</label>' => '<div class="input-group">'
194  . '<input class="form-control" type="text" name="kernel" id="kernel" '
195  . 'value="'
196  . $kernel
197  . '"/>'
198  . '</div>',
199  '<label for="kernargs">'
200  . _('Kernel Arguments')
201  . '</label>' => '<div class="input-group">'
202  . '<input class="form-control" type="text" name="kernelargs" id='
203  . '"kernargs" value="'
204  . $kernelargs
205  . '"/>'
206  . '</div>',
207  '<label for="initrd">'
208  . _('Init')
209  . '</label>' => '<div class="input-group">'
210  . '<textarea name="initrd" class='
211  . '"form-control" id="initrd">'
212  . $initrd
213  . '</textarea>'
214  . '</div>',
215  '<label for="type">'
216  . _('Type')
217  . '</label>' => '<div class="input-group">'
218  . '<input class="form-control" type="text" name="type" id='
219  . '"type" value="'
220  . $type
221  . '"/>'
222  . '</div>',
223  '<label for="isAd">'
224  . _('Is Advanced')
225  . '</label>' => '<input type="checkbox" name="advanced" id='
226  . '"isAd"'
227  . $isAd
228  . '/>',
229  '<label for="access">'
230  . _('Accessed By')
231  . '</label>' => $accessSel,
232  '<label for="add">'
233  . _('Create Task type')
234  . '</label>' => '<button class="btn btn-info btn-block" type="submit" '
235  . 'id="add" name="add">'
236  . _('Add')
237  . '</button>'
238  );
239  self::$HookManager
240  ->processEvent(
241  'TASKTYPE_FIELDS',
242  array(
243  'fields' => &$fields,
244  'TaskType' => self::getClass('TaskType')
245  )
246  );
247  array_walk($fields, $this->fieldsToData);
248  self::$HookManager
249  ->processEvent(
250  'TASKTYPE_ADD',
251  array(
252  'headerData' => &$this->headerData,
253  'data' => &$this->data,
254  'templates' => &$this->templates,
255  'attributes' => &$this->attributes
256  )
257  );
258  echo '<div class="col-xs-9">';
259  echo '<div class="panel panel-info">';
260  echo '<div class="panel-heading text-center">';
261  echo '<h4 class="title">';
262  echo $this->title;
263  echo '</h4>';
264  echo '</div>';
265  echo '<div class="panel-body">';
266  echo '<form class="form-horizontal" method="post" action="'
267  . $this->formAction
268  . '">';
269  $this->render(12);
270  echo '</form>';
271  echo '</div>';
272  echo '</div>';
273  echo '</div>';
274  }
280  public function addPost()
281  {
282  $name = filter_input(
283  INPUT_POST,
284  'name'
285  );
286  $description = filter_input(
287  INPUT_POST,
288  'description'
289  );
290  $icon = filter_input(
291  INPUT_POST,
292  'icon'
293  );
294  $kernel = filter_input(
295  INPUT_POST,
296  'kernel'
297  );
298  $kernelargs = filter_input(
299  INPUT_POST,
300  'kernelargs'
301  );
302  $initrd = filter_input(
303  INPUT_POST,
304  'initrd'
305  );
306  $type = filter_input(
307  INPUT_POST,
308  'type'
309  );
310  $access = filter_input(
311  INPUT_POST,
312  'access'
313  );
314  $advanced = isset($_POST['advanced']);
315  try {
316  if (self::getClass('TaskTypeManager')->exists($name)) {
317  throw new Exception(
318  _('A task type already exists with this name!')
319  );
320  }
321  $TaskType = self::getClass('TaskType')
322  ->set('name', $name)
323  ->set('description', $description)
324  ->set('icon', $icon)
325  ->set('kernel', $kernel)
326  ->set('kernelArgs', $kernelargs)
327  ->set('initrd', $initrd)
328  ->set('type', $type)
329  ->set('isAdvanced', $advanced)
330  ->set('access', $access);
331  if (!$TaskType->save()) {
332  throw new Exception(_('Add task type failed!'));
333  }
334  $hook = 'TASK_TYPE_ADD_SUCCESS';
335  $msg = json_encode(
336  array(
337  'msg' => _('Task Type added!'),
338  'title' => _('Task Type Create Success')
339  )
340  );
341  } catch (Exception $e) {
342  $hook = 'TASK_TYPE_ADD_FAIL';
343  $msg = json_encode(
344  array(
345  'error' => $e->getMessage(),
346  'title' => _('Task Type Create Fail')
347  )
348  );
349  }
350  self::$HookManager
351  ->processEvent(
352  $hook,
353  array('TaskType' => &$TaskType)
354  );
355  unset($TaskType);
356  echo $msg;
357  exit;
358  }
364  public function taskTypeGeneral()
365  {
366  unset(
367  $this->data,
368  $this->form,
369  $this->templates,
370  $this->attributes,
371  $this->headerData
372  );
373  $name = (
374  filter_input(
375  INPUT_POST,
376  'name'
377  ) ?: $this->obj->get('name')
378  );
379  $description = (
380  filter_input(
381  INPUT_POST,
382  'description'
383  ) ?: $this->obj->get('description')
384  );
385  $icon = (
386  filter_input(
387  INPUT_POST,
388  'icon'
389  ) ?: $this->obj->get('icon')
390  );
391  $kernel = (
392  filter_input(
393  INPUT_POST,
394  'kernel'
395  ) ?: $this->obj->get('kernel')
396  );
397  $kernelargs = (
398  filter_input(
399  INPUT_POST,
400  'kernelargs'
401  ) ?: $this->obj->get('kernelargs')
402  );
403  $initrd = (
404  filter_input(
405  INPUT_POST,
406  'initrd'
407  ) ?: $this->obj->get('initrd')
408  );
409  $type = (
410  filter_input(
411  INPUT_POST,
412  'type'
413  ) ?: $this->obj->get('type')
414  );
415  $access = (
416  filter_input(
417  INPUT_POST,
418  'access'
419  ) ?: $this->obj->get('access')
420  );
421  $advanced = (
422  isset($_POST['advanced']) ?: $this->obj->get('advanced')
423  );
424  $isAd = (
425  $advanced ?
426  ' checked' :
427  ''
428  );
429  $accessTypes = array(
430  'both',
431  'host',
432  'group'
433  );
434  $accessSel = self::selectForm(
435  'access',
436  $accessTypes,
437  $access
438  );
439  unset($accessTypes);
440  $this->attributes = array(
441  array('class' => 'col-xs-4'),
442  array('class' => 'col-xs-8 form-group'),
443  );
444  $this->templates = array(
445  '${field}',
446  '${input}',
447  );
448  $fields = array(
449  '<label for="name">'
450  . _('Name')
451  . '</label>' => '<div class="input-group">'
452  . '<input type="text" name="name" id="name" value="'
453  . $name
454  . '" class="form-control" autocomplete="off" '
455  . 'required/>'
456  . '</div>',
457  '<label for="description">'
458  . _('Description')
459  . '</label>' => '<div class="input-group">'
460  . '<textarea name="description" id="description" class="form-control">'
461  . $description
462  . '</textarea>'
463  . '</div>',
464  '<label for="icon">'
465  . _('Icon')
466  . '</label>' => self::getClass('TaskType')->iconlist($icon),
467  '<label for="kernel">'
468  . _('Kernel')
469  . '</label>' => '<div class="input-group">'
470  . '<input class="form-control" type="text" name="kernel" id="kernel" '
471  . 'value="'
472  . $kernel
473  . '"/>'
474  . '</div>',
475  '<label for="kernargs">'
476  . _('Kernel Arguments')
477  . '</label>' => '<div class="input-group">'
478  . '<input class="form-control" type="text" name="kernelargs" id='
479  . '"kernargs" value="'
480  . $kernelargs
481  . '"/>'
482  . '</div>',
483  '<label for="initrd">'
484  . _('Init')
485  . '</label>' => '<div class="input-group">'
486  . '<textarea name="initrd" class='
487  . '"form-control" id="initrd">'
488  . $initrd
489  . '</textarea>'
490  . '</div>',
491  '<label for="type">'
492  . _('Type')
493  . '</label>' => '<div class="input-group">'
494  . '<input class="form-control" type="text" name="type" id='
495  . '"type" value="'
496  . $type
497  . '"/>'
498  . '</div>',
499  '<label for="isAd">'
500  . _('Is Advanced')
501  . '</label>' => '<input type="checkbox" name="advanced" id='
502  . '"isAd"'
503  . $isAd
504  . '/>',
505  '<label for="access">'
506  . _('Accessed By')
507  . '</label>' => $accessSel,
508  '<label for="update">'
509  . _('Make Changes?')
510  . '</label>' => '<button class="btn btn-info btn-block" type="submit" '
511  . 'id="update" name="update">'
512  . _('Update')
513  . '</button>'
514  );
515  self::$HookManager
516  ->processEvent(
517  'TASKTYPE_FIELDS',
518  array(
519  'fields' => &$fields,
520  'TaskType' => self::getClass('TaskState')
521  )
522  );
523  array_walk($fields, $this->fieldsToData);
524  self::$HookManager
525  ->processEvent(
526  'TASKTYPE_EDIT',
527  array(
528  'data' => &$this->data,
529  'templates' => &$this->templates,
530  'attributes' => &$this->attributes,
531  'headerData' => &$this->headerData
532  )
533  );
534  echo '<!-- General -->';
535  echo '<div class="tab-pane fade in active" id="tasktype-gen">';
536  echo '<div class="panel panel-info">';
537  echo '<div class="panel-heading text-center">';
538  echo '<h4 class="title">';
539  echo _('Task Type General');
540  echo '</h4>';
541  echo '</div>';
542  echo '<div class="panel-body">';
543  echo '<form class="form-horizontal" method="post" action="'
544  . $this->formAction
545  . '&tab="taskstate-gen">';
546  $this->render(12);
547  echo '</form>';
548  echo '</div>';
549  echo '</div>';
550  echo '</div>';
551  unset(
552  $this->data,
553  $this->form,
554  $this->templates,
555  $this->attributes,
556  $this->headerData
557  );
558  }
564  public function edit()
565  {
566  echo '<div class="col-xs-9 tab-content">';
567  $this->taskTypeGeneral();
568  echo '</div>';
569  }
575  public function editPost()
576  {
577  self::$HookManager
578  ->processEvent(
579  'TASKTYPE_EDIT_POST',
580  array('TaskType' => &$this->obj)
581  );
582  $name = filter_input(
583  INPUT_POST,
584  'name'
585  );
586  $description = filter_input(
587  INPUT_POST,
588  'description'
589  );
590  $icon = filter_input(
591  INPUT_POST,
592  'icon'
593  );
594  $kernel = filter_input(
595  INPUT_POST,
596  'kernel'
597  );
598  $kernelargs = filter_input(
599  INPUT_POST,
600  'kernelargs'
601  );
602  $initrd = filter_input(
603  INPUT_POST,
604  'initrd'
605  );
606  $type = filter_input(
607  INPUT_POST,
608  'type'
609  );
610  $access = filter_input(
611  INPUT_POST,
612  'access'
613  );
614  $advanced = isset($_POST['advanced']);
615  try {
616  if ($this->obj->get('name') != $name
617  && self::getClass('TaskTypeManager')->exists($name)
618  ) {
619  throw new Exception(
620  _('A task type already exists with this name!')
621  );
622  }
623  $this->obj
624  ->set('name', $name)
625  ->set('description', $description)
626  ->set('icon', $icon)
627  ->set('kernel', $kernel)
628  ->set('kernelArgs', $kernelargs)
629  ->set('initrd', $initrd)
630  ->set('type', $type)
631  ->set('isAdvanced', $advanced)
632  ->set('access', $access);
633  if (!$this->obj->save()) {
634  throw new Exception(_('Update task state failed!'));
635  }
636  $hook = 'TASK_TYPE_EDIT_SUCCESS';
637  $msg = json_encode(
638  array(
639  'msg' => _('Task Type Updated!'),
640  'title' => _('Task Type Update Success')
641  )
642  );
643  } catch (Exception $e) {
644  $hook = 'TASK_TYPE_EDIT_FAIL';
645  $msg = json_encode(
646  array(
647  'error' => $e->getMessage(),
648  'title' => _('Task Type Update Fail')
649  )
650  );
651  }
652  self::$HookManager
653  ->processEvent(
654  $hook,
655  array('TaskType' => &$this->obj)
656  );
657  echo $msg;
658  exit;
659  }
660 }
FOGController\save
save()
Definition: fogcontroller.class.php:387
FOGPage\render
render($colsize=9)
Definition: fogpage.class.php:605
TasktypeeditManagementPage\taskTypeGeneral
taskTypeGeneral()
Definition: tasktypeeditmanagementpage.class.php:364
exit
exit
Definition: download.php:102
FOGPage\selectForm
static selectForm( $name, $items=array(), $selected='', $useidsel=false, $addClass='')
Definition: fogpage.class.php:4052
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGPage\$title
$title
Definition: fogpage.class.php:49
TasktypeeditManagementPage\$node
$node
Definition: tasktypeeditmanagementpage.class.php:29
TasktypeeditManagementPage\addPost
addPost()
Definition: tasktypeeditmanagementpage.class.php:280
TasktypeeditManagementPage\editPost
editPost()
Definition: tasktypeeditmanagementpage.class.php:575
FOGPage\$name
$name
Definition: fogpage.class.php:31
$TaskType
if(FOGCore::$useragent) if(! $Task->isValid()) $TaskType
Definition: hostinfo.php:33
TasktypeeditManagementPage
Definition: tasktypeeditmanagementpage.class.php:23
FOGPage
Definition: fogpage.class.php:25
FOGPage\$id
$id
Definition: fogpage.class.php:43
TasktypeeditManagementPage\__construct
__construct($name='')
Definition: tasktypeeditmanagementpage.class.php:37
TasktypeeditManagementPage\edit
edit()
Definition: tasktypeeditmanagementpage.class.php:564
$foglang
$foglang['Display']
Definition: text.php:22
$msg
if($Host->isValid()) $msg
Definition: hostnameloop.php:42
TasktypeeditManagementPage\add
add()
Definition: tasktypeeditmanagementpage.class.php:111