/** edit() Creates the form and display for editing an existing image object. */ public function edit() { // Find $Image = $this->obj; // Title - set title for page title in window $this->title = sprintf('%s: %s', _('Edit'), $Image->get('name')); print "\n\t\t\t" . '<div id="tab-container">'; // Unset the headerData unset($this->headerData); // Set the table row information $this->attributes = array(array(), array()); // Set the template information $this->templates = array('${field}', '${input}'); // Set the fields and inputs. $fields = array(_('Image Name') => '<input type="text" name="name" id="iName" onblur="duplicateImageName()" value="${image_name}" />', _('Image Description') => '<textarea name="description" rows="8" cols="40">${image_desc}</textarea>', _('Operating System') => '${operating_systems}', _('Image Path') => '${image_path}<input type="text" name="file" id="iFile" value="${image_file}" />', _('Image Type') => '${image_types}', _('Partition') => '${image_partition_types}', _('Protected') => '<input type="checkbox" name="protected_image" value="1" ${image_protected} />', _('Compression') => '<div id="pigz" style="width: 200px; top: 15px;"></div><input type="text" readonly="true" name="compress" id="showVal" maxsize="1" style="width: 10px; top: -5px; left: 225px; position: relative;" value="${image_comp}" />', $_SESSION['FOG_FORMAT_FLAG_IN_GUI'] ? _('Image Manager') : '' => $_SESSION['FOG_FORMAT_FLAG_IN_GUI'] ? '<select name="imagemanage"><option value="1" ${is_legacy}>' . _('PartImage') . '</option><option value="0" ${is_modern}>' . _('PartClone') . '</option></select>' : '', '<input type="hidden" name="add" value="1" />' => '<input type="submit" value="' . _('Update') . '" /><!--<i class="icon fa fa-question" title="TODO!"></i>-->'); $StorageNode = $Image->getStorageGroup()->getMasterStorageNode(); foreach ((array) $fields as $field => $input) { $this->data[] = array('field' => $field, 'input' => $input, 'image_name' => $Image->get('name'), 'image_desc' => $Image->get('description'), 'operating_systems' => $this->getClass('OSManager')->buildSelectBox($Image->get('osID')), 'image_path' => $StorageNode && $StorageNode->isValid() ? $StorageNode->get('path') . '/ ' : 'No nodes available.', 'image_file' => $Image->get('path'), 'image_types' => $this->getClass('ImageTypeManager')->buildSelectBox($Image->get('imageTypeID'), '', 'id'), 'image_partition_types' => $this->getClass('ImagePartitionTypeManager')->buildSelectBox($Image->get('imagePartitionTypeID'), '', 'id'), 'is_legacy' => $Image->get('format') == 1 ? 'selected="selected"' : '', 'is_modern' => $Image->get('format') == 0 ? 'selected="selected"' : '', 'image_protected' => $Image->get('protected') ? 'checked' : '', 'image_comp' => is_numeric($Image->get('compress')) && $Image->get('compress') > -1 ? $Image->get('compress') : $this->FOGCore->getSetting('FOG_PIGZ_COMP')); } // Hook $this->HookManager->processEvent('IMAGE_EDIT', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); // Output print "\n\t\t\t<!-- General -->"; print "\n\t\t\t" . '<div id="image-gen">'; print "\n\t\t\t<h2>" . _('Edit image definition') . '</h2>'; print "\n\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=image-gen">'; $this->render(); print '</form>'; print "\n\t\t\t\t</div>"; // Reset for next tab unset($this->data); print "\n\t\t\t\t<!-- Storage Groups with Assigned Image -->"; $IAMan = new ImageAssociationManager(); $SGMan = new StorageGroupManager(); // Get groups with this image assigned foreach ((array) $Image->get('storageGroups') as $Group) { if ($Group && $Group->isValid()) { $GroupsWithMe[] = $Group->get('id'); } } // Get all group IDs with an image assigned foreach ($IAMan->find() as $Group) { if ($Group->getStorageGroup() && $Group->getStorageGroup()->isValid() && $Group->getImage()->isValid()) { $GroupWithAnyImage[] = $Group->getStorageGroup()->get('id'); } } // Set the values foreach ($SGMan->find() as $Group) { if ($Group && $Group->isValid()) { if (!in_array($Group->get('id'), $GroupWithAnyImage)) { $GroupNotWithImage[] = $Group; } if (!in_array($Group->get('id'), $GroupsWithMe)) { $GroupNotWithMe[] = $Group; } } } print "\n\t\t\t\t" . '<div id="image-storage">'; // Create the header data: $this->headerData = array('<input type="checkbox" name="toggle-checkboxgroup1" class="toggle-checkbox1" />', _('Storage Group Name')); // Create the template data: $this->templates = array('<input type="checkbox" name="storagegroup[]" value="${storageGroup_id}" class="toggle-group${check_num}" />', '${storageGroup_name}'); // Create the attributes data: $this->attributes = array(array('class' => 'c', 'width' => 16), array()); // All groups not with this set as the image foreach ((array) $GroupNotWithMe as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name'), 'check_num' => 1); } } $GroupDataExists = false; if (count($this->data) > 0) { $GroupDataExists = true; $this->HookManager->processEvent('IMAGE_GROUP_ASSOC', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); print "\n\t\t\t<center>" . '<label for="groupMeShow">' . _('Check here to see groups not assigned with this image') . ' <input type="checkbox" name="groupMeShow" id="groupMeShow" /></label>'; print "\n\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=image-storage">'; print "\n\t\t\t" . '<div id="groupNotInMe">'; print "\n\t\t\t" . '<h2>' . _('Modify group association for') . ' ' . $Image->get('name') . '</h2>'; print "\n\t\t\t" . '<p>' . _('Add image to groups') . ' ' . $Image->get('name') . '</p>'; $this->render(); print "</div>"; } // Reset the data for the next value unset($this->data); // Create the header data: $this->headerData = array('<input type="checkbox" name="toggle-checkboxgroup2" class="toggle-checkbox2" />', _('Storage Group Name')); // All groups without an image foreach ((array) $GroupNotWithImage as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name'), 'check_num' => '2'); } } if (count($this->data) > 0) { $GroupDataExists = true; $this->HookManager->processEvent('IMAGE_GROUP_NOT_WITH_ANY', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); print "\n\t\t\t" . '<label for="groupNoShow">' . _('Check here to see groups not with any image associated') . ' <input type="checkbox" name="groupNoShow" id="groupNoShow" /></label>'; print "\n\t\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=image-storage">'; print "\n\t\t\t" . '<div id="groupNoImage">'; print "\n\t\t\t" . '<p>' . _('Groups below have no image association') . '</p>'; print "\n\t\t\t" . '<p>' . _('Assign image to groups') . ' ' . $Image->get('name') . '</p>'; $this->render(); print "\n\t\t\t</div>"; } if ($GroupDataExists) { print '<br/><input type="submit" value="' . _('Add Image to Group(s)') . '" />'; print "\n\t\t\t</form></center>"; } unset($this->data); $this->headerData = array('<input type="checkbox" name="toggle-checkbox" class="toggle-checkboxAction" checked/>', _('Storage Group Name')); $this->attributes = array(array('width' => 16, 'class' => 'c'), array('class' => 'r')); $this->templates = array('<input type="checkbox" class="toggle-action" name="storagegroup-rm[]" value="${storageGroup_id}" checked/>', '${storageGroup_name}'); foreach ((array) $Image->get('storageGroups') as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name')); } } // Hook $this->HookManager->processEvent('IMAGE_EDIT_GROUP', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); // Output print "\n\t\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=image-storage">'; $this->render(); if (count($this->data) > 0) { print "\n\t\t\t" . '<center><input type="submit" value="' . _('Delete Selected Group associations') . '" name="remstorgroups"/></center>'; } print '</form>'; print "\n\t\t\t\t</div>"; print "\n\t\t\t</div>"; }
public function edit() { // Find $Snapin = $this->obj; // Title $this->title = sprintf('%s: %s', _('Edit'), $Snapin->get('name')); // Header Data unset($this->headerData); // Attributes (cell information) $this->attributes = array(array(), array()); // Template $this->templates = array('${field}', '${input}'); // See's what files are available and sorts them. if ($Snapin->get('storageGroups')) { foreach ((array) $Snapin->get('storageGroups') as $StorageGroup) { $StorageNode = $StorageGroup->getMasterStorageNode(); if ($StorageNode && $StorageNode->isValid()) { $this->FOGFTP->set('host', $StorageNode->get('ip'))->set('username', $StorageNode->get('user'))->set('password', $StorageNode->get('pass'))->connect(); $filelist = $this->FOGFTP->nlist($StorageNode->get('snapinpath')); foreach ($filelist as $file) { if (!$this->FOGFTP->chdir($file)) { $files[] = basename($file); } } } $this->FOGFTP->close(); } unset($filelist); $filelist = $files; } else { // See's what files are available and sorts them. $files = array_diff(preg_grep('#^([^.])#', scandir($_SESSION['FOG_SNAPINDIR'])), array('..', '.')); foreach ($files as $file) { if (!is_dir(rtrim($_SESSION['FOG_SNAPINDIR'], '/') . '/' . $file)) { $filelist[] = $file; } } } sort($filelist); foreach ((array) $filelist as $file) { $filesFound .= '<option value="' . basename($file) . '" ' . (basename($file) == basename($Snapin->get('file')) ? 'selected="selected"' : '') . '>' . basename($file) . '</option>'; } // Fields to work from: $fields = array(_('Snapin Name') => '<input type="text" name="name" value="${snapin_name}" />', _('Snapin Description') => '<textarea name="description" rows="8" cols="40" value="${snapin_desc}">${snapin_desc}</textarea>', _('Snapin Run With') => '<input type="text" name="rw" value="${snapin_rw}" />', _('Snapin Run With Argument') => '<input type="text" name="rwa" value="${snapin_rwa}" />', _('Snapin File') . ' <span class="lightColor">' . _('Max Size') . ':${max_size}</span>' => '<span id="uploader">${snapin_file}<a href="#" id="snapin-upload"><i class="fa fa-arrow-up noBorder"></i></a></span>', count($files) > 0 ? _('Snapin File (exists)') : null => count($files) > 0 ? '<select name="snapinfileexist"><<span class="lightColor"><option value="">- ' . _('Please select an option') . '-</option>${snapin_filesexist}</select>' : null, _('Snapin Arguments') => '<input type="text" name="args" value="${snapin_args}" />', _('Protected') => '<input type="checkbox" name="protected_snapin" value="1" ${snapin_protected} />', _('Reboot after install') => '<input type="checkbox" name="reboot" ${checked} />', '<input type="hidden" name="snapinid" value="${snapin_id}" /><input type="hidden" name="update" value="1" />' => '<input type="hidden" name="snapinfile" value="${snapin_file}" /><input type="submit" value="' . _('Update') . '" />'); print "\n\t\t\t" . '<div id="tab-container">'; print "\n\t\t\t\t" . '<!-- General -->'; print "\n\t\t\t\t" . '<div id="snap-gen">'; print "\n\t\t\t\t" . '<form method="post" action="' . $this->formAction . '&id=' . $Snapin->get('id') . '&tab=snap-gen" enctype="multipart/form-data">'; foreach ((array) $fields as $field => $input) { $this->data[] = array('field' => $field, 'input' => $input, 'snapin_id' => $Snapin->get('id'), 'snapin_name' => $Snapin->get('name'), 'snapin_desc' => $Snapin->get('description'), 'snapin_rw' => $Snapin->get('runWith'), 'snapin_rwa' => htmlentities($Snapin->get('runWithArgs')), 'snapin_args' => $Snapin->get('args'), 'max_size' => ini_get('post_max_size'), 'snapin_file' => $Snapin->get('file'), 'snapin_filesexist' => $filesFound, 'snapin_protected' => $Snapin->get('protected') ? 'checked' : '', 'checked' => $Snapin->get('reboot') ? 'checked' : ''); } // Hook $this->HookManager->processEvent('SNAPIN_EDIT', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); // Output $this->render(); print '</form>'; print "\n\t\t\t</div>"; unset($this->data); print "\n\t\t\t\t<!-- Storage Groups with Assigned Image -->"; $SGAMan = new SnapinGroupAssociationManager(); $SGMan = new StorageGroupManager(); // Get groups with this snapin assigned foreach ((array) $Snapin->get('storageGroups') as $Group) { if ($Group && $Group->isValid()) { $GroupsWithMe[] = $Group->get('id'); } } // Get all group IDs with a snapin assigned foreach ($SGAMan->find() as $Group) { if ($Group->getStorageGroup() && $Group->getStorageGroup()->isValid() && $Group->getSnapin()->isValid()) { $GroupWithAnySnapin[] = $Group->getStorageGroup()->get('id'); } } // Set the values foreach ($SGMan->find() as $Group) { if ($Group && $Group->isValid()) { if (!in_array($Group->get('id'), $GroupWithAnySnapin)) { $GroupNotWithSnapin[] = $Group; } if (!in_array($Group->get('id'), $GroupsWithMe)) { $GroupNotWithMe[] = $Group; } } } print "\n\t\t\t\t" . '<div id="snap-storage">'; // Create the Header Data: $this->headerData = array('<input type="checkbox" name="toggle-checkboxsnapin1" class="toggle-checkbox1"/>', _('Storage Group Name')); // Create the template data: $this->templates = array('<input type="checkbox" name="storagegroup[]" value="${storageGroup_id}" class="toggle-snapin${check_num}" />', '${storageGroup_name}'); // Create the attributes data: $this->attributes = array(array('class' => 'c', 'width' => 16), array()); // All Groups not with this set as the Snapin foreach ((array) $GroupNotWithMe as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name'), 'check_num' => 1); } } $GroupDataExists = false; if (count($this->data) > 0) { $GroupDataExists = true; $this->HookManager->processEvent('SNAPIN_GROUP_ASSOC', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); print "\n\t\t\t<center>" . '<label for="groupMeShow">' . _('Check here to see groups not assigned with this snapin') . ' <input type="checkbox" name="groupMeShow" id="groupMeShow" /></label>'; print "\n\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=snap-storage">'; print "\n\t\t\t" . '<div id="groupNotInMe">'; print "\n\t\t\t" . '<h2>' . _('Modify group association for') . ' ' . $Snapin->get('name') . '</h2>'; print "\n\t\t\t" . '<p>' . _('Add snapin to groups') . ' ' . $Snapin->get('name') . '</p>'; $this->render(); print '</div>'; } // Reset the data for the next value unset($this->data); // Create the header data: $this->headerData = array('<input type="checkbox" name="toggle-checkboxgroup2" class="toggle-checkbox2"/>', _('Storage Group Name')); // All groups without a snapin foreach ((array) $GroupNotWithSnapin as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name'), 'check_num' => 2); } } if (count($this->data) > 0) { $GroupDataExists = true; $this->HookManager->processEvent('SNAPIN_GROUP_NOT_WITH_ANY', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); print "\n\t\t\t" . '<label for="groupNoShow">' . _('Check here to see groups not with any snapin associated') . ' <input type="checkbox" name="groupNoShow" id="groupNoShow" /></label'; print "\n\t\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=snap-storage">'; print "\n\t\t\t" . '<div id="groupNoSnapin">'; print "\n\t\t\t" . '<p>' . _('Groups below have no snapin association') . '</p>'; print "\n\t\t\t" . '<p>' . _('Assign snapin to groups') . ' ' . $Snapin->get('name') . '</p>'; $this->render(); print "\n\t\t\t</div>"; } if ($GroupDataExists) { print '<br/><input type="submit" value="' . _('Add Snapin to Group(s)') . '" />'; print "\n\t\t\t</form></center>"; } $this->headerData = array('<input type="checkbox" name="toggle-checkbox" class="toggle-checkboxAction" checked/>', _('Storage Group Name')); $this->attributes = array(array('width' => 16, 'class' => 'c'), array('class' => 'r')); $this->templates = array('<input type="checkbox" class="toggle-action" name="storagegroup-rm[]" value="${storageGroup_id}" checked/>', '${storageGroup_name}'); unset($this->data); foreach ((array) $Snapin->get('storageGroups') as $Group) { if ($Group && $Group->isValid()) { $this->data[] = array('storageGroup_id' => $Group->get('id'), 'storageGroup_name' => $Group->get('name')); } } // Hook $this->HookManager->processEvent('SNAPIN_EDIT_GROUP', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes)); // Output print "\n\t\t\t\t" . '<form method="post" action="' . $this->formAction . '&tab=snap-storage">'; $this->render(); if (count($this->data) > 0) { print "\n\t\t\t" . '<center><input type="submit" value="' . _('Delete Selected Group associations') . '" name="remstorgroups"/></center>'; } print '</form>'; print "\n\t\t\t\t</div>"; print "\n\t\t\t" . '</div>'; }