ID = $id; } public function getID($hideAutoID = true) { return $this->ID; } public function setButtonID($id) { $this->buttonID = $id; } public function getButtonID() { return $this->buttonID; } public function setWindowTitle($param) { $this->windowTitle = $param; } public function getWindowTitle() { return $this->windowTitle; } public function prepareData($sender, $param) { $this->setPoolList(); $params = $this->getUrlParams(array('volumes'), $this->getPage()->VolumeWindow->ID); $volumes = $this->Application->getModule('api')->get($params); $isDetailView = $_SESSION['view' . $this->getPage()->VolumeWindow->ID] == 'details'; if($isDetailView === true) { $this->RepeaterShow->Visible = false; $this->DataGridShow->Visible = true; $this->DataGrid->DataSource = $this->Application->getModule('misc')->objectToArray($volumes->output); $this->DataGrid->dataBind(); } else { $this->Repeater->DataSource = $volumes->output; $this->Repeater->dataBind(); $this->RepeaterShow->Visible = true; $this->DataGridShow->Visible = false; } } private function setPoolList() { $pools = $this->Application->getModule('api')->get(array('pools')); for ($i = 0; $i < count($pools->output); $i++) { $this->pools[$pools->output[$i]->poolid] = $pools->output[$i]->name; } } protected function sortData($data, $key, $id) { if($this->getSortOrder($id) == parent::SORT_DESC) { if($key == 'pool') { $key = 'name'; $compare = create_function('$a,$b','if ($a["pool"]["'.$key.'"] == $b["pool"]["'.$key.'"]) {return 0;}else {return ($a["pool"]["'.$key.'"] < $b["pool"]["'.$key.'"]) ? 1 : -1;}'); } else { $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] < $b["'.$key.'"]) ? 1 : -1;}'); } } else { if($key == 'pool') { $key = 'name'; $compare = create_function('$a,$b','if ($a["pool"]["'.$key.'"] == $b["pool"]["'.$key.'"]) {return 0;}else {return ($a["pool"]["'.$key.'"] > $b["pool"]["'.$key.'"]) ? 1 : -1;}'); } else { $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] > $b["'.$key.'"]) ? 1 : -1;}'); } } usort($data,$compare); return $data; } public function sortDataGrid($sender, $param) { $params = $this->getUrlParams(array('volumes'), $this->getPage()->VolumeWindow->ID); $data = $this->Application->getModule('api')->get($params)->output; $data = $this->Application->getModule('misc')->objectToArray($data); $this->DataGrid->DataSource = $this->sortData($data, $param->SortExpression, $sender->UniqueID); $this->DataGrid->dataBind(); } public function configure($sender, $param) { if($this->Page->IsCallBack) { $this->getPage()->VolumeConfiguration->configure($param->CallbackParameter); } } public function executeAction($action) { $params = explode(';', $this->CheckedValues->Value); $commands = array(); switch($action) { case 'prune': { for($i = 0; $i < count($params); $i++) { $cmd = array('prune'); $cmd[] = 'volume="' . $params[$i] . '"'; $cmd[] = 'yes'; $cmd[] = PHP_EOL; $commands[] = implode(' ', $cmd); } $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); $this->getPage()->Console->sendCommand(null, null); break; } case 'purge': { for($i = 0; $i < count($params); $i++) { $cmd = array('purge'); $cmd[] = 'volume="' . $params[$i] . '"'; $cmd[] = 'yes'; $cmd[] = PHP_EOL; $commands[] = implode(' ', $cmd); } $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); $this->getPage()->Console->sendCommand(null, null); break; } case 'delete': { for($i = 0; $i < count($params); $i++) { $cmd = array('delete'); $cmd[] = 'volume="' . $params[$i] . '"'; $cmd[] = 'yes'; $cmd[] = PHP_EOL; $commands[] = implode(' ', $cmd); } $this->getPage()->Console->CommandLine->Text = implode(' ', $commands); $this->getPage()->Console->sendCommand(null, null); break; } } $this->CheckedValues->Value = ""; } public function formatVolumeField($name) { if (strlen($name) > 20) { $name = substr($name, 0, 7) . '...' . substr($name, -10); } return $name; } } ?>