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)  

taskmanagementpage.class.php
Go to the documentation of this file.
1 <?php
23 {
29  public $node = 'task';
37  public function __construct($name = '')
38  {
39  $this->name = 'Task Management';
40  parent::__construct($this->name);
41  $this->menu = array(
42  'active' => self::$foglang['ActiveTasks'],
43  'listhosts' => sprintf(
44  self::$foglang['ListAll'],
45  self::$foglang['Hosts']
46  ),
47  'listgroups' => sprintf(
48  self::$foglang['ListAll'],
49  self::$foglang['Groups']
50  ),
51  'activemulticast' => self::$foglang['ActiveMCTasks'],
52  'activesnapins' => self::$foglang['ActiveSnapins'],
53  'activescheduled' => self::$foglang['ScheduledTasks'],
54  );
55  self::$HookManager
56  ->processEvent(
57  'SUB_MENULINK_DATA',
58  array(
59  'menu' => &$this->menu,
60  'submenu' => &$this->subMenu,
61  'id' => &$this->id,
62  'notes' => &$this->notes
63  )
64  );
65  $this->headerData = array(
66  '<input type="checkbox" class="toggle-checkboxAction" id="toggler"/>'
67  . '<label for="toggler"></label>',
68  _('Started By:'),
69  sprintf(
70  '%s<br/><small>%s</small>',
71  _('Hostname'),
72  _('MAC')
73  ),
74  _('Image Name'),
75  _('Start Time'),
76  _('Working with node'),
77  _('Status')
78  );
79  $this->templates = array(
80  '<input type="checkbox" class="toggle-action" name='
81  . '"task[]" value="${id}" id="tasker-${id}"/><label for="'
82  . 'tasker-${id}"></label>',
83  '${startedby}',
84  sprintf(
85  '<p><a href="?node=host&sub=edit&id=${host_id}" title='
86  . '"%s">${host_name}</a></p><small>${host_mac}</small>',
87  _('Edit Host')
88  ),
89  sprintf(
90  '<p><a href="?node=image&sub=edit&id=${image_id}" title='
91  . '"%s">${image_name}</a></p>',
92  _('Edit Image')
93  ),
94  '<small>${time}</small>',
95  '<small>${node_name}</small>',
96  '${details_taskforce} <i data-state="${state_id}" class='
97  . '"state fa fa-${icon_state} fa-1x icon" title="${state}">'
98  . '</i> <i class="fa fa-${icon_type} fa-1x icon" title="${type}"></i>',
99  );
100  $this->attributes = array(
101  array(
102  'width' => 16,
103  'class' => 'filter-false',
104  'task-id' => '${id}'
105  ),
106  array(
107  'width' => 65,
108  'id' => 'host-${host_id}'
109  ),
110  array(
111  'width' => 120,
112  ),
113  array(
114  'width' => 70,
115  ),
116  array(
117  'width' => 100,
118  ),
119  array(
120  'width' => 70,
121  ),
122  array(
123  'width' => 50,
124  'class' => 'filter-false'
125  ),
126  );
134  self::$returnData = function (&$Task) {
135  $tmpTask = self::getClass(
136  'Task',
137  $Task->id
138  );
139  $SnapinTrue = $tmpTask->isSnapinTasking();
140  if ($SnapinTrue) {
142  'SnapinJob',
143  $Task->host->snapinjob->id
144  );
145  if ($SnapinJob->isValid()) {
146  $STCount = self::getClass('SnapinTaskManager')
147  ->count(
148  array(
149  'jobID' => $SnapinJob->get('id'),
150  'stateID' => self::fastmerge(
151  (array)$this->getQueuedStates(),
152  (array)$this->getProgressState()
153  )
154  )
155  );
156  if ($STCount < 1) {
157  $tmpTask->cancel();
158  return;
159  }
160  }
161  }
162  if ($Task->state->id < 3) {
163  if ($Task->type->id < 3) {
164  if ($Task->isForced) {
165  $forcetask = sprintf(
166  '<i class="icon-forced" title="%s"></i>',
167  _('Task forced to start')
168  );
169  } else {
170  $forcetask = sprintf(
171  '<i class="icon-force icon" title="%s" href="?%s"></i>',
172  _('Force task to start'),
173  'node=task&sub=forceTask&id=${id}'
174  );
175  }
176  }
177  }
178  $this->data[] = array(
179  'startedby' => $Task->createdBy,
180  'details_taskforce' => $forcetask,
181  'id' => $Task->id,
182  'name' => $Task->name,
183  'time' => self::formatTime(
184  $Task->createdTime,
185  'Y-m-d H:i:s'
186  ),
187  'state' => $Task->state->name,
188  'forced' => $Task->isForced,
189  'type' => $Task->type->name,
190  'elapsed' => $Task->timeElapsed,
191  'remains' => $Task->timeRemaining,
192  'percent' => $Task->pct,
193  'copied' => $Task->dataCopied,
194  'total' => $Task->dataTotal,
195  'bpm' => $Task->bpm,
196  'details_taskname' => (
197  $Task->name ?
198  sprintf(
199  '<div class="task-name">%s</div>',
200  $Task->name
201  ) :
202  ''
203  ),
204  'host_id' => $Task->host->id,
205  'host_name' => $Task->host->name,
206  'host_mac' => $Task->host->mac,
207  'icon_state' => $Task->state->icon,
208  'icon_type' => $Task->type->icon,
209  'state_id' => $Task->state->id,
210  'image_name' => $Task->image->name,
211  'image_id' => $Task->image->id,
212  'node_name' => $Task->storagenode->name
213  );
214  unset($tmpTask, $Task);
215  };
216  }
222  public function index()
223  {
224  $this->active();
225  }
231  public function searchPost()
232  {
233  $this->data = array();
234  array_shift($this->headerData);
235  array_shift($this->templates);
236  array_shift($this->attributes);
237  parent::searchPost();
238  }
244  public function active()
245  {
246  $this->title = _('Active Tasks');
247  $this->data = array();
248  $find = array(
249  'stateID' => self::fastmerge(
250  (array) self::getQueuedStates(),
251  (array) self::getProgressState()
252  )
253  );
254  Route::active('task');
255  $items = json_decode(
257  );
258  $items = $items->tasks;
259  if (count($items) > 0) {
260  array_walk(
261  $items,
262  static::$returnData
263  );
264  }
265  self::$HookManager
266  ->processEvent(
267  'HOST_DATA',
268  array(
269  'headerData' => &$this->headerData,
270  'data' => &$this->data,
271  'templates' => &$this->templates,
272  'attributes' => &$this->attributes
273  )
274  );
275  unset($items);
276  if (self::$ajax) {
277  return $this->render();
278  }
279  $this->displayActive();
280  unset(
281  $this->data,
282  $this->form,
283  $this->headerData,
284  $this->templates,
285  $this->attributes
286  );
287  }
293  public function displayActive()
294  {
295  echo '<div class="tab-content col-xs-9">';
296  echo '<div class="panel panel-info">';
297  echo '<div class="panel-heading text-center">';
298  echo '<h4 class="title">';
299  echo $this->title;
300  echo '</h4>';
301  echo '</div>';
302  echo '<div class="panel-body">';
303  $this->render(12);
304  echo '</div>';
305  echo '</div>';
306  echo '</div>';
307  }
313  public function listhosts()
314  {
315  unset(
316  $this->data,
317  $this->form,
318  $this->headerData,
319  $this->attributes,
320  $this->templates
321  );
322  $this->title = _('All Hosts');
323  $up = new TaskType(2);
324  $down = new TaskType(1);
325  $up = sprintf(
326  '<a href="?node=task&sub=hostdeploy&type=%s&id=${id}">'
327  . '<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
328  $up->get('id'),
329  $up->get('icon'),
330  $up->get('name')
331  );
332  $down = sprintf(
333  '<a href="?node=task&sub=hostdeploy&type=%s&id=${id}">'
334  . '<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
335  $down->get('id'),
336  $down->get('icon'),
337  $down->get('name')
338  );
339  $adv = sprintf(
340  '<a href="?node=task&sub=hostadvanced&id=${id}#host-tasks">'
341  . '<i class="icon hand fa fa-arrows-alt fa-fw title="%s"></i></a>',
342  _('Advanced')
343  );
344  $this->headerData = array(
345  _('Host Name'),
346  _('Assigned Image'),
347  _('Tasking'),
348  );
349  $this->templates = array(
350  '<a href="?node=host&sub=edit&id=${id}">${name}</a>'
351  . '<br/><small>${mac}</small>',
352  '<small>${imagename}</small>',
353  sprintf(
354  '%s %s %s',
355  $down,
356  $up,
357  $adv
358  ),
359  );
360  $this->attributes = array(
361  array(
362  'width' => 100,
363  'class' => 'i'
364  ),
365  array(
366  'width' => 60,
367  ),
368  array(
369  'width' => 60,
370  'class' => 'filter-false'
371  ),
372  );
374  'host',
375  'name',
376  false,
377  array('pending' => array('0', '', null))
378  );
379  $Hosts = json_decode(
381  );
382  $Hosts = $Hosts->hosts;
383  foreach ((array)$Hosts as &$Host) {
384  $this->data[] = array(
385  'id' => $Host->id,
386  'name' => $Host->name,
387  'mac' => $Host->primac,
388  'imagename' => $Host->image->name,
389  );
390  unset($Host);
391  }
392  self::$HookManager
393  ->processEvent(
394  'HOST_DATA',
395  array(
396  'headerData' => &$this->headerData,
397  'data' => &$this->data,
398  'templates' => &$this->templates,
399  'attributes' => &$this->attributes
400  )
401  );
402  unset($Hosts);
403  $this->displayActive();
404  unset(
405  $this->data,
406  $this->form,
407  $this->headerData,
408  $this->attributes,
409  $this->templates
410  );
411  }
417  public function listgroups()
418  {
419  unset(
420  $this->data,
421  $this->form,
422  $this->headerData,
423  $this->templates,
424  $this->attributes
425  );
426  $this->title = _('All Groups');
427  $mc = new TaskType(8);
428  $down = new TaskType(1);
429  $mc = sprintf(
430  '<a href="?node=task&sub=groupdeploy&type=%s&id=${id}">'
431  . '<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
432  $mc->get('id'),
433  $mc->get('icon'),
434  $mc->get('name')
435  );
436  $down = sprintf(
437  '<a href="?node=task&sub=groupdeploy&type=%s&id=${id}">'
438  . '<i class="icon hand fa fa-%s fa-fw" title="%s"></i></a>',
439  $down->get('id'),
440  $down->get('icon'),
441  $down->get('name')
442  );
443  $adv = sprintf(
444  '<a href="?node=task&sub=groupadvanced&id=${id}#group-tasks">'
445  . '<i class="icon hand fa fa-arrows-alt fa-fw title="%s"></i></a>',
446  _('Advanced')
447  );
448  $this->headerData = array(
449  _('Group Name'),
450  _('Tasking'),
451  );
452  $this->templates = array(
453  '<a href="?node=group&sub=edit&id=${id}">${name}</a>',
454  sprintf(
455  '%s %s %s',
456  $mc,
457  $down,
458  $adv
459  ),
460  );
461  $this->attributes = array(
462  array(
463  'width' => 100,
464  'class' => 'i'
465  ),
466  array(
467  'width' => 60,
468  'class' => 'filter-false'
469  ),
470  );
471  Route::listem('group');
472  $Groups = json_decode(
474  );
475  $Groups = $Groups->groups;
476  foreach ((array)$Groups as &$Group) {
477  $this->data[] = array(
478  'id' => $Group->id,
479  'name' => $Group->name,
480  );
481  unset($Group);
482  }
483  self::$HookManager
484  ->processEvent(
485  'TasksListGroupData',
486  array(
487  'headerData' => &$this->headerData,
488  'data' => &$this->data,
489  'templates' => &$this->templates,
490  'attributes' => &$this->attributes
491  )
492  );
493  unset($Groups);
494  $this->displayActive();
495  unset(
496  $this->data,
497  $this->form,
498  $this->headerData,
499  $this->templates,
500  $this->attributes
501  );
502  }
510  private function _tasking($type)
511  {
512  global $id;
513  try {
514  $types = array(
515  'host',
516  'group'
517  );
518  if (!in_array($type, $types)) {
519  throw new Exception(_('Invalid object type passed'));
520  }
521  $var = ucfirst($type);
522  $$var = self::getClass($var, $id);
523  if (!$$var->isValid()) {
524  throw new Exception(_(sprintf('Invalid %s', $var)));
525  }
526  $typeID = filter_input(INPUT_GET, 'type');
527  $TaskType = new TaskType($typeID);
528  if (!$TaskType->isValid()) {
529  throw new Exception(_('Invalid Task Type'));
530  }
531  if ($type == 'host') {
532  $Image = $$var->getImage();
533  if (!$Image->isValid()) {
534  throw new Exception(_('Invalid image assigned to host'));
535  }
536  if ($TaskType->isCapture()
537  && $Image->get('protected')
538  ) {
539  throw new Exception(
540  sprintf(
541  '%s: %s %s',
542  _('Image'),
543  $Image->get('name'),
544  _('is protected')
545  )
546  );
547  }
548  $taskName = sprintf(
549  '%s %s',
550  _('Quick'),
551  $TaskType->get('name')
552  );
553  } elseif ($type == 'group') {
554  if ($TaskType->isMulticast()
555  && !$$var->doMembersHaveUniformImages()
556  ) {
557  throw new Exception(
558  _('Hosts do not have the same image assigned')
559  );
560  }
561  $taskName = (
563  _('Multicast Quick Deploy') :
564  _('Group Quick Deploy')
565  );
566  }
567  $enableSnapins = $TaskType->get('id') == 17 ? false : -1;
568  $enableDebug = in_array(
569  $TaskType->get('id'),
570  array(3, 15, 16)
571  );
572  $$var->createImagePackage(
573  $TaskType->get('id'),
574  $taskName,
575  false,
576  $enableDebug,
577  $enableSnapins,
578  $type === 'group',
579  self::$FOGUser->get('name'),
580  false,
581  false,
582  $TaskType->isInitNeededTasking() || $TaskType->get('id') == 14
583  );
584  echo '<div class="col-xs-9">';
585  echo '<div class="panel panel-success">';
586  echo '<div class="panel-heading text-center">';
587  echo '<h4 class="title">';
588  echo _('Tasked Successfully');
589  echo '</h4>';
590  echo '</div>';
591  echo '<div class="panel-body">';
592  echo _('Tasked successfully, click active tasks to view in line.');
593  echo '</div>';
594  echo '</div>';
595  echo '</div>';
596  } catch (Exception $e) {
597  echo '<div class="col-xs-9">';
598  echo '<div class="panel panel-warning">';
599  echo '<div class="panel-heading text-center">';
600  echo '<h4 class="title">';
601  echo _('Failed to create task');
602  echo '</h4>';
603  echo '</div>';
604  echo '<div class="panel-body">';
605  echo $e->getMessage();
606  echo '</div>';
607  echo '</div>';
608  echo '</div>';
609  }
610  }
616  public function hostdeploy()
617  {
618  $this->_tasking('host');
619  }
625  public function groupdeploy()
626  {
627  $this->_tasking('group');
628  }
637  private function _advanced($type)
638  {
639  unset(
640  $this->data,
641  $this->form,
642  $this->headerData,
643  $this->templates,
644  $this->attributes
645  );
646  $this->title = _(
647  sprintf(
648  '%s Advanced Actions',
649  ucfirst($type)
650  )
651  );
652  global $id;
653  $types = array(
654  'host',
655  'group'
656  );
657  if (!in_array($type, $types)) {
658  throw new Exception(_('Invalid object type passed'));
659  }
660  $this->templates = array(
661  sprintf(
662  '<a href="?node=%s&sub=%sdeploy&id=${id}&type=${type}">'
663  . '<i class="fa fa-${icon} fa-fw fa-2x"/></i><br/>${name}</a>',
664  $this->node,
665  $type
666  ),
667  '${description}',
668  );
669  $this->attributes = array(
670  array('class' => 'col-xs-4'),
671  array('class' => 'col-xs-8 form-group'),
672  );
674  'tasktype',
675  'id',
676  false,
677  array(
678  'access' => array('both', $type),
679  'isAdvanced' => 1
680  )
681  );
682  $TaskTypes = json_decode(
684  );
685  $TaskTypes = $TaskTypes->tasktypes;
686  foreach ((array)$TaskTypes as &$TaskType) {
687  $this->data[] = array(
688  'id' => $id,
689  'type' => $TaskType->id,
690  'icon' => $TaskType->icon,
691  'name' => $TaskType->name,
692  'description' => $TaskType->description
693  );
694  unset($TaskType);
695  }
696  self::$HookManager
697  ->processEvent(
698  'TASK_DATA',
699  array(
700  'headerData' => &$this->headerData,
701  'data' => &$this->data,
702  'templates' => &$this->templates,
703  'attributes' => &$this->attributes
704  )
705  );
706  unset($TaskTypes);
707  $this->displayActive();
708  unset(
709  $this->data,
710  $this->form,
711  $this->headerData,
712  $this->templates,
713  $this->attributes
714  );
715  }
721  public function hostadvanced()
722  {
723  $this->_advanced('host');
724  }
730  public function groupadvanced()
731  {
732  $this->_advanced('group');
733  }
739  public function activePost()
740  {
741  if (!self::$ajax) {
742  $this->_nonajax();
743  }
744  self::getClass('TaskManager')->cancel($_POST['task']);
745  exit;
746  }
752  public function forceTask()
753  {
754  global $id;
755  try {
756  $Task = new Task($id);
757  if (!$Task->isValid()) {
758  throw new Exception(_('Invalid task'));
759  }
760  self::$HookManager
761  ->processEvent(
762  'TASK_FORCE',
763  array(
764  'Task' => &$Task
765  )
766  );
767  $Task->set('isForced', 1)->save();
768  $result['success'] = true;
769  } catch (Exception $e) {
770  $result['error'] = $e->getMessage();
771  }
772  if (self::$ajax) {
773  echo json_encode($result);
774  exit;
775  }
776  if ($result['error']) {
777  self::fatalError($result['error']);
778  } else {
780  sprintf(
781  '?node=%s',
782  $this->node
783  )
784  );
785  }
786  }
792  public function activemulticast()
793  {
794  unset(
795  $this->data,
796  $this->form,
797  $this->headerData,
798  $this->attributes,
799  $this->templates
800  );
801  $this->title = _('Active Multi-cast Tasks');
802  $this->headerData = array(
803  '<input type="checkbox" name="toggle-checkbox" class='
804  . '"toggle-checkboxAction" id="toggler1"/>'
805  . '<label for="toggler1"></label>',
806  _('Task Name'),
807  _('Hosts'),
808  _('Start Time'),
809  _('State'),
810  _('Status'),
811  );
812  $this->templates = array(
813  '<input type="checkbox" name="task[]" value="${id}" class='
814  . '"toggle-action" id="mctask-${id}"/>'
815  . '<label for="mctask-${id}"></label>',
816  '${name}',
817  '${count}',
818  '${start_date}',
819  '${state}',
820  '${percent}',
821  );
822  $this->attributes = array(
823  array(
824  'width' => 16,
825  'class' => 'filter-false',
826  'task-id' => '${id}'
827  ),
828  array(
829  ),
830  array(
831  ),
832  array(
833  ),
834  array(
835  ),
836  array(
837  'width' => 40
838  )
839  );
840  Route::active('multicastsession');
841  $Sessions = json_decode(
843  );
844  $Sessions = $Sessions->multicastsessions;
845  foreach ((array)$Sessions as &$MulticastSession) {
846  $TaskState = $MulticastSession->state;
847  if (!$TaskState->id) {
848  continue;
849  }
850  $this->data[] = array(
851  'id' => $MulticastSession->id,
852  'name' => (
853  $MulticastSession->name ?: _('MulticastTask')
854  ),
855  'count' => (
856  self::getClass('MulticastSessionAssociationManager')
857  ->count(array('msID' => $MulticastSession->id))
858  ),
859  'start_date' => self::formatTime(
860  $MulticastSession->starttime,
861  'Y-m-d H:i:s'
862  ),
863  'state' => (
864  $TaskState->name ?: ''
865  ),
866  'percent' => $MulticastSession->percent,
867  );
868  unset($TaskState, $MulticastSession);
869  }
870  self::$HookManager
871  ->processEvent(
872  'TaskActiveMulticastData',
873  array(
874  'headerData' => &$this->headerData,
875  'data' => &$this->data,
876  'templates' => &$this->templates,
877  'attributes' => &$this->attributes
878  )
879  );
880  unset($Sessions);
881  if (self::$ajax) {
882  return $this->render();
883  }
884  $this->displayActive();
885  unset(
886  $this->data,
887  $this->form,
888  $this->headerData,
889  $this->attributes,
890  $this->templates
891  );
892  }
898  public function activemulticastPost()
899  {
900  if (!self::$ajax) {
901  $this->_nonajax();
902  }
903  $MulticastSessionIDs = (array)$_POST['task'];
904  $TaskIDs = self::getSubObjectIDs(
905  'MulticastSessionAssociation',
906  array(
907  'msID' => $MulticastSessionIDs
908  ),
909  'taskID'
910  );
911  self::getClass('TaskManager')->cancel($TaskIDs);
912  self::getClass('MulticastSessionManager')->cancel($_POST['task']);
913  unset($MulticastSessionIDs);
914  exit;
915  }
921  public function activesnapins()
922  {
923  unset(
924  $this->data,
925  $this->form,
926  $this->headerData,
927  $this->attributes,
928  $this->templates
929  );
930  $this->title = 'Active Snapins';
931  $this->headerData = array(
932  '<input type="checkbox" name="toggle-checkbox" class='
933  . '"toggle-checkboxAction" id="toggler2"/><label for="'
934  . 'toggler2"></label>',
935  _('Host Name'),
936  _('Snapin'),
937  _('Start Time'),
938  _('State'),
939  );
940  $this->templates = array(
941  '<input type="checkbox" name="task[]" value="${id}" class='
942  . '"toggle-action" id="sntasks-${id}"/><label for="'
943  . 'sntasks-${id}"></label>',
944  sprintf(
945  '<p><a href="?node=host&sub=edit&id=${host_id}" title='
946  . '"%s">${host_name}</a></p><small>${host_mac}</small>',
947  _('Edit Host')
948  ),
949  '${name}',
950  '${startDate}',
951  '${state}',
952  );
953  $this->attributes = array(
954  array(
955  'class' => 'filter-false',
956  'width' => 16,
957  'task-id'=>'${id}'
958  ),
959  array(
960  'width' => 50
961  ),
962  array(
963  'width' => 50
964  ),
965  array(
966  'width' => 50
967  ),
968  array(
969  'width' => 40
970  )
971  );
972  Route::active('snapintask');
973  $SnapinTasks = json_decode(
975  );
976  $activestate = self::fastmerge(
977  (array)self::getQueuedStates(),
978  (array)self::getProgressState()
979  );
980  $SnapinTasks = $SnapinTasks->snapintasks;
981  foreach ((array)$SnapinTasks as &$SnapinTask) {
982  $Snapin = $SnapinTask->snapin;
983  if (!$Snapin->id) {
984  continue;
985  }
986  $SnapinJob = $SnapinTask->snapinjob;
987  if (!$SnapinJob->id) {
988  continue;
989  }
990  Route::indiv('host', $SnapinJob->hostID);
991  $Host = json_decode(
993  );
994  if (!$Host->id) {
995  continue;
996  }
997  $state = $SnapinJob->stateID;
998  $inArr = in_array($state, $activestate);
999  if (!$inArr) {
1000  continue;
1001  }
1002  $this->data[] = array(
1003  'id' => $SnapinTask->id,
1004  'name' => $Snapin->name,
1005  'host_id' => $Host->id,
1006  'host_name' => $Host->name,
1007  'host_mac' => $Host->primac,
1008  'startDate' => self::formatTime(
1009  $SnapinTask->checkin,
1010  'Y-m-d H:i:s'
1011  ),
1012  'state' => $SnapinTask->state->name
1013  );
1014  unset(
1015  $SnapinTask,
1016  $Snapin,
1017  $SnapinJob,
1018  $Host
1019  );
1020  }
1021  self::$HookManager
1022  ->processEvent(
1023  'TaskActiveSnapinsData',
1024  array(
1025  'headerData' => &$this->headerData,
1026  'data' => &$this->data,
1027  'templates' => &$this->templates,
1028  'attributes' => &$this->attributes
1029  )
1030  );
1031  unset($SnapinTasks);
1032  if (self::$ajax) {
1033  return $this->render();
1034  }
1035  $this->displayActive();
1036  unset(
1037  $this->data,
1038  $this->form,
1039  $this->headerData,
1040  $this->attributes,
1041  $this->templates
1042  );
1043  }
1049  private function _nonajax()
1050  {
1052  _('Cannot cancel tasks this way')
1053  );
1054  self::redirect($this->formAction);
1055  }
1061  public function activesnapinsPost()
1062  {
1063  if (!self::$ajax) {
1064  $this->_nonajax();
1065  }
1066  $SnapinTaskIDs = (array)$_POST['task'];
1067  if (count($SnapinTaskIDs) > 0) {
1068  $SnapinJobIDs = self::getSubObjectIDs(
1069  'SnapinTask',
1070  array(
1071  'id' => $SnapinTaskIDs
1072  ),
1073  'jobID'
1074  );
1075  self::getClass('SnapinTaskManager')->cancel($SnapinTaskIDs);
1076  }
1077  if (count($SnapinJobIDs) > 0) {
1078  $HostIDs = self::getSubObjectIDs(
1079  'SnapinJob',
1080  array(
1081  'id' => $SnapinJobIDs
1082  ),
1083  'hostID'
1084  );
1085  }
1086  if (count($HostIDs) > 0) {
1087  $SnapTaskIDs = self::getSubObjectIDs(
1088  'SnapinTask',
1089  array(
1090  'jobID' => $SnapinJobIDs,
1091  )
1092  );
1093  $TaskIDs = array_diff(
1094  $SnapTaskIDs,
1095  $SnapinTaskIDs
1096  );
1097  }
1098  if (count($TaskIDs) < 1) {
1099  $TaskIDs = self::getSubObjectIDs(
1100  'Task',
1101  array(
1102  'hostID' => $HostIDs,
1103  'typeID' => array(
1104  12,
1105  13
1106  )
1107  )
1108  );
1109  self::getClass('TaskManager')->cancel($TaskIDs);
1110  }
1111  exit;
1112  }
1118  public function activescheduled()
1119  {
1120  unset(
1121  $this->data,
1122  $this->form,
1123  $this->headerData,
1124  $this->attributes,
1125  $this->templates
1126  );
1127  $this->title = _('Scheduled Tasks');
1128  $this->headerData = array(
1129  '<input type="checkbox" name="toggle-checkbox" class='
1130  . '"toggle-checkboxAction" id="toggler3"/><label for="'
1131  . 'toggler3"></label>',
1132  _('Host/Group Name'),
1133  _('Is Group'),
1134  _('Task Name'),
1135  _('Task Type'),
1136  _('Start Time'),
1137  _('Active'),
1138  _('Type'),
1139  );
1140  $this->templates = array(
1141  '<input type="checkbox" name="task[]" value="${id}" class='
1142  . '"toggle-action" id="sctasks-${id}"/><label for="'
1143  . 'sctasks-${id}"></label>',
1144  '<a href="?node=${hostgroup}&sub=edit&id=${hostgroupid}" title='
1145  . '"Edit ${nametype}: ${hostgroupname}">${hostgroupname}</a>${extra}',
1146  '${groupbased}',
1147  '<span class="icon" title="${hover}">${details_taskname}</span>',
1148  '${task_type}',
1149  '<small>${start_time}</small>',
1150  '${active}',
1151  '${type}',
1152  );
1153  $this->attributes = array(
1154  array(
1155  'width' => 16,
1156  'class' => 'filter-false',
1157  'task-id' => '${id}'
1158  ),
1159  array(
1160  'width' => 100
1161  ),
1162  array(
1163  'width' => 25
1164  ),
1165  array(
1166  'width' => 110
1167  ),
1168  array(
1169  'width' => 80
1170  ),
1171  array(
1172  'width' => 70
1173  ),
1174  array(
1175  'width' => 30
1176  ),
1177  array(
1178  'width' => 80
1179  )
1180  );
1181  Route::active('scheduledtask');
1182  $ScheduledTasks = json_decode(
1183  Route::getData()
1184  );
1185  $ScheduledTasks = $ScheduledTasks->scheduledtasks;
1186  foreach ((array)$ScheduledTasks as &$ScheduledTask) {
1187  $method = 'host';
1188  if ($ScheduledTask->isGroupTask) {
1189  $method = 'group';
1190  }
1191  $ObjTest = $ScheduledTask->{$method};
1192  if (!$ObjTest->id) {
1193  continue;
1194  }
1195  $TaskType = $ScheduledTask->tasktype;
1196  if (!$TaskType->id) {
1197  continue;
1198  }
1199  $sID = $ScheduledTask->other2;
1200  if ($TaskType->isSnapinTasking) {
1201  if ($TaskType->id == 12
1202  || $ScheduledTask->other2 == -1
1203  ) {
1204  $hover = _('All snapins');
1205  } elseif ($TaskType->id == 13) {
1206  $snapin = new Snapin($sID);
1207  if (!$snapin->isValid()) {
1208  $hover = _('Invalid snapin');
1209  } else {
1210  $hover = _('Snapin to be installed')
1211  . ': '
1212  . $snapin->get('name');
1213  }
1214  }
1215  }
1216  $this->data[] = array(
1217  'id' => $ScheduledTask->id,
1218  'start_time' => $ScheduledTask->runtime,
1219  'groupbased' => (
1220  $ScheduledTask->isGroupTask ?
1221  _('Yes') :
1222  _('No')
1223  ),
1224  'active' => (
1225  $ScheduledTask->isActive ?
1226  _('Yes') :
1227  _('No')
1228  ),
1229  'type' => $ScheduledTask->type == 'C' ? _('Cron') : _('Delayed'),
1230  'hostgroup' => (
1231  $ScheduledTask->isGroupTask ?
1232  _('group') :
1233  _('host')
1234  ),
1235  'hostgroupname' => $ObjTest->name,
1236  'hostgroupid' => $ObjTest->id,
1237  'details_taskname' => $ScheduledTask->name,
1238  'task_type' => $TaskType->name,
1239  'extra' => (
1240  $ScheduledTask->isGroupTask ?
1241  '' :
1242  sprintf(
1243  '<br/>%s',
1244  $ObjTest->primac
1245  )
1246  ),
1247  'nametype' => $method,
1248  'hover' => $hover
1249  );
1250  unset($ScheduledTask, $ObjTest, $TaskType);
1251  }
1252  self::$HookManager
1253  ->processEvent(
1254  'TaskScheduledData',
1255  array(
1256  'headerData' => &$this->headerData,
1257  'data' => &$this->data,
1258  'templates' => &$this->templates,
1259  'attributes' => &$this->attributes
1260  )
1261  );
1262  if (self::$ajax) {
1263  return $this->render();
1264  }
1265  $this->displayActive();
1266  unset(
1267  $this->data,
1268  $this->form,
1269  $this->headerData,
1270  $this->attributes,
1271  $this->templates
1272  );
1273  }
1279  public function activescheduledPost()
1280  {
1281  if (!self::$ajax) {
1282  $this->_nonajax();
1283  }
1284  self::getClass('ScheduledTaskManager')
1285  ->destroy(
1286  array('id' => $_POST['task'])
1287  );
1288  exit;
1289  }
1290 }
FOGBase\fatalError
static fatalError($txt, $data=array())
Definition: fogbase.class.php:700
TaskManagementPage\displayActive
displayActive()
Definition: taskmanagementpage.class.php:293
FOGPage\render
render($colsize=9)
Definition: fogpage.class.php:605
exit
exit
Definition: download.php:102
TaskManagementPage\activescheduled
activescheduled()
Definition: taskmanagementpage.class.php:1118
TaskManagementPage\_advanced
_advanced($type)
Definition: taskmanagementpage.class.php:637
TaskType\isCapture
isCapture($nums=false)
Definition: tasktype.class.php:150
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
FOGBase\fastmerge
static fastmerge($array1)
Definition: fogbase.class.php:2415
Route\active
static active($class)
Definition: route.class.php:1104
TaskType
Definition: tasktype.class.php:23
Host\isValid
isValid()
Definition: host.class.php:622
FOGPage\$title
$title
Definition: fogpage.class.php:49
Snapin
Definition: snapin.class.php:23
TaskManagementPage\groupadvanced
groupadvanced()
Definition: taskmanagementpage.class.php:730
Route\indiv
static indiv($class, $id, $item='')
Definition: route.class.php:562
TaskManagementPage\hostadvanced
hostadvanced()
Definition: taskmanagementpage.class.php:721
TaskManagementPage\listgroups
listgroups()
Definition: taskmanagementpage.class.php:417
$SnapinJob
if(!FOGCore::$Host->isValid()) $SnapinJob
Definition: snapcheck.php:28
TaskManagementPage\activemulticastPost
activemulticastPost()
Definition: taskmanagementpage.class.php:898
$items
$items
Definition: boot.php:24
TaskType\isInitNeededTasking
isInitNeededTasking($nums=false)
Definition: tasktype.class.php:180
TaskManagementPage
Definition: taskmanagementpage.class.php:23
FOGPage\$name
$name
Definition: fogpage.class.php:31
FOGController\get
get($key='')
Definition: fogcontroller.class.php:207
TaskManagementPage\_nonajax
_nonajax()
Definition: taskmanagementpage.class.php:1049
TaskManagementPage\activesnapins
activesnapins()
Definition: taskmanagementpage.class.php:921
TaskManagementPage\activemulticast
activemulticast()
Definition: taskmanagementpage.class.php:792
TaskManagementPage\$node
$node
Definition: taskmanagementpage.class.php:29
TaskManagementPage\index
index()
Definition: taskmanagementpage.class.php:222
TaskManagementPage\active
active()
Definition: taskmanagementpage.class.php:244
Task
Definition: task.class.php:23
$TaskType
if(FOGCore::$useragent) if(! $Task->isValid()) $TaskType
Definition: hostinfo.php:33
TaskManagementPage\activescheduledPost
activescheduledPost()
Definition: taskmanagementpage.class.php:1279
TaskManagementPage\activePost
activePost()
Definition: taskmanagementpage.class.php:739
FOGBase\redirect
static redirect($url='')
Definition: fogbase.class.php:831
FOGPage
Definition: fogpage.class.php:25
TaskManagementPage\__construct
__construct($name='')
Definition: taskmanagementpage.class.php:37
Route\getData
static getData()
Definition: route.class.php:1173
TaskType\isMulticast
isMulticast($nums=false)
Definition: tasktype.class.php:285
TaskManagementPage\searchPost
searchPost()
Definition: taskmanagementpage.class.php:231
TaskManagementPage\listhosts
listhosts()
Definition: taskmanagementpage.class.php:313
TaskManagementPage\groupdeploy
groupdeploy()
Definition: taskmanagementpage.class.php:625
FOGPage\$id
$id
Definition: fogpage.class.php:43
Route\listem
static listem( $class, $sortby='name', $bypass=false, $find=array(), $item='')
Definition: route.class.php:429
TaskManagementPage\activesnapinsPost
activesnapinsPost()
Definition: taskmanagementpage.class.php:1061
$Image
$Image
Definition: hostinfo.php:37
$Task
$Task
Definition: hostinfo.php:26
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
FOGBase\$Host
static $Host
Definition: fogbase.class.php:312
$foglang
$foglang['Display']
Definition: text.php:22
TaskManagementPage\hostdeploy
hostdeploy()
Definition: taskmanagementpage.class.php:616
FOGBase\setMessage
static setMessage($txt, $data=array())
Definition: fogbase.class.php:784
FOGController\isValid
isValid()
Definition: fogcontroller.class.php:865
TaskType\isSnapinTasking
isSnapinTasking($nums=false)
Definition: tasktype.class.php:207
TaskManagementPage\_tasking
_tasking($type)
Definition: taskmanagementpage.class.php:510
TaskManagementPage\forceTask
forceTask()
Definition: taskmanagementpage.class.php:752