function select()
 {
     $h = array();
     $h['file']['title'] = $this->lang['table_file'];
     $h['distribution']['title'] = $this->lang['table_distribution'];
     $h['application']['title'] = $this->lang['table_application'];
     $h['size']['title'] = $this->lang['table_size'];
     $h['password']['title'] = $this->lang['table_password'];
     $h['maintainer']['title'] = $this->lang['table_maintainer'];
     $h['edit']['title'] = ' ';
     $h['edit']['sortable'] = false;
     $b = array();
     require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
     $imageshelf = new imageshelf();
     $imageshelf->get_instance_by_id($this->id);
     $file = $this->openqrm->get('basedir') . '/plugins/image-shelf/web/image-lists/' . $imageshelf->name . '/image-shelf.conf';
     if ($this->file->exists($file)) {
         $this->file->remove($file);
     }
     $command = $this->openqrm->get('basedir') . '/plugins/image-shelf/bin/openqrm-image-shelf list';
     $command .= ' -n ' . $imageshelf->name;
     $command .= ' -i ' . $imageshelf->uri;
     $command .= ' -u ' . $imageshelf->user;
     $command .= ' -p ' . $imageshelf->password;
     $command .= ' --openqrm-ui-user ' . $this->user->name;
     $command .= ' --openqrm-cmd-mode background';
     $openqrm_server = new openqrm_server();
     $openqrm_server->send_command($command);
     while (!$this->file->exists($file)) {
         usleep(10000);
         // sleep 10ms to unload the CPU
         clearstatcache();
     }
     sleep(1);
     $lines = explode("\n", $this->file->get_contents($file));
     foreach ($lines as $line) {
         if ($line !== '') {
             $tmp = explode('|', $line);
             $a = $this->response->html->a();
             $a->title = $this->lang['action_edit'];
             $a->label = $this->lang['action_edit'];
             $a->handler = 'onclick="wait();"';
             $a->css = 'edit';
             $a->href = $this->response->get_url($this->actions_name, "target") . '&file=' . $tmp[0];
             $b[] = array('file' => $tmp[0], 'distribution' => $tmp[1], 'application' => $tmp[3], 'size' => $tmp[4], 'password' => $tmp[5], 'maintainer' => $tmp[6], 'edit' => $a->get_string());
         }
     }
     $table = $this->response->html->tablebuilder('imageshelf_template', $this->response->get_array($this->actions_name, 'template'));
     $table->offset = 0;
     $table->sort = 'file';
     $table->limit = 10;
     $table->order = 'ASC';
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->autosort = true;
     $table->sort_link = false;
     $table->max = count($b);
     $table->head = $h;
     $table->body = $b;
     $d['table'] = $table;
     $d['name'] = $imageshelf->name;
     $d['form'] = $this->response->get_form($this->actions_name, 'template', false)->get_elements();
     return $d;
 }
 function add()
 {
     $response = $this->get_response();
     $form = $response->form;
     if (!$form->get_errors() && $this->response->submit()) {
         require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
         $imageshelf = new imageshelf();
         $fields = $form->get_request();
         // handle url
         if ($fields['imageshelf_protocol'] === 'local' && !preg_match('~^/~', $fields['imageshelf_uri'])) {
             $fields['imageshelf_uri'] = '/' . $fields['imageshelf_uri'];
         }
         $fields['imageshelf_id'] = (int) str_replace(".", "", str_pad(microtime(true), 15, "0"));
         $fields['imageshelf_uri'] = $fields['imageshelf_protocol'] . '://' . $fields['imageshelf_uri'];
         $imageshelf->add($fields);
         $response->msg = sprintf($this->lang['msg'], $fields['imageshelf_name']);
     }
     return $response;
 }
 function select()
 {
     $d = array();
     $id = $this->response->html->request()->get('image_id');
     if ($id !== '') {
         $image = new image();
         $image->get_instance_by_id($id);
         $storage = new storage();
         $storage->get_instance_by_id($image->storageid);
         $resource = new resource();
         $resource->get_instance_by_id($storage->resource_id);
         require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
         $imageshelf = new imageshelf();
         $imageshelf->get_instance_by_id($this->id);
         $file = $this->openqrm->get('basedir') . '/plugins/image-shelf/web/image-lists/' . $imageshelf->name . '/image-shelf.conf';
         if ($this->file->exists($file)) {
             $this->file->remove($file);
         }
         $command = $this->openqrm->get('basedir') . '/plugins/image-shelf/bin/openqrm-image-shelf list';
         $command .= ' -n ' . $imageshelf->name;
         $command .= ' -i ' . $imageshelf->uri;
         $command .= ' -u ' . $imageshelf->user;
         $command .= ' -p ' . $imageshelf->password;
         $command .= ' --openqrm-ui-user ' . $this->user->name;
         $command .= ' --openqrm-cmd-mode background';
         $openqrm_server = new openqrm_server();
         $openqrm_server->send_command($command);
         while (!$this->file->exists($file)) {
             usleep(10000);
             // sleep 10ms to unload the CPU
             clearstatcache();
         }
         sleep(1);
         $distribution = '';
         $lines = explode("\n", $this->file->get_contents($file));
         foreach ($lines as $line) {
             $tmp = explode('|', $line);
             if (isset($tmp[0]) && $tmp[0] === $this->image) {
                 $distribution = $tmp[1];
                 break;
             }
         }
         $command = $this->openqrm->get('basedir') . '/plugins/image-shelf/bin/openqrm-image-shelf get';
         $command .= ' -n ' . $imageshelf->name;
         $command .= ' -i ' . $imageshelf->uri;
         $command .= ' -f ' . $this->image;
         $command .= ' -s ' . $resource->ip . ':' . $image->rootdevice;
         $command .= ' -d ' . $distribution;
         $command .= ' -u ' . $imageshelf->user;
         $command .= ' -p ' . $imageshelf->password;
         $command .= ' -o ' . $this->openqrm->admin()->name . ' -q ' . $this->openqrm->admin()->password;
         $command .= ' --openqrm-ui-user ' . $this->user->name;
         $command .= ' --openqrm-cmd-mode background';
         $openqrm_server->send_command($command);
         $d = sprintf($this->lang['msg'], $image->name, $this->image);
     } else {
         $h = array();
         $h['image_icon']['title'] = ' ';
         $h['image_icon']['sortable'] = false;
         $h['image_id']['title'] = $this->lang['table_id'];
         $h['image_name']['title'] = $this->lang['table_name'];
         $h['image_version']['title'] = $this->lang['table_version'];
         $h['image_type']['title'] = $this->lang['table_deployment'];
         $h['image_isactive']['title'] = $this->lang['table_isactive'];
         $h['image_comment']['title'] = $this->lang['table_comment'];
         $h['image_comment']['sortable'] = false;
         $h['edit']['title'] = ' ';
         $h['edit']['sortable'] = false;
         $image = new image();
         $params = $this->response->get_array($this->actions_name, 'target');
         $b = array();
         $table = $this->response->html->tablebuilder('imageshelf_target', $params);
         $table->offset = 0;
         $table->sort = 'image_id';
         $table->limit = 10;
         $table->order = 'ASC';
         $table->max = $image->get_count();
         $table->init();
         $image_arr = $image->display_overview(0, 10000, $table->sort, $table->order);
         $image_icon = "/openqrm/base/img/image.png";
         foreach ($image_arr as $index => $image_db) {
             // prepare the values for the array
             $image = new image();
             $image->get_instance_by_id($image_db["image_id"]);
             if ($image->type === 'lvm-nfs-deployment' || $image->type === 'nfs-deployment') {
                 $image_comment = $image_db["image_comment"];
                 if (!strlen($image_comment)) {
                     $image_comment = "-";
                 }
                 $image_version = $image_db["image_version"];
                 if (!strlen($image_version)) {
                     $image_version = "-";
                 }
                 // edit
                 $a = $this->response->html->a();
                 $a->title = $this->lang['action_edit'];
                 $a->handler = 'onclick="wait();"';
                 $a->css = 'edit';
                 $a->href = $this->response->get_url($this->actions_name, 'target') . '&image_id=' . $image->id;
                 $image_edit = $a->get_string();
                 // set the active icon
                 $isactive_icon = "/openqrm/base/img/enable.png";
                 if ($image_db["image_isactive"] == 1) {
                     $isactive_icon = "/openqrm/base/img/disable.png";
                 }
                 $image_isactive_icon = "<img src=" . $isactive_icon . " width='24' height='24' alt='State'>";
                 $b[] = array('image_icon' => "<img width='24' height='24' src='" . $image_icon . "'>", 'image_id' => $image_db["image_id"], 'image_name' => $image_db["image_name"], 'image_version' => $image_version, 'image_type' => $image_db["image_type"], 'image_isactive' => $image_isactive_icon, 'image_comment' => $image_comment, 'edit' => $image_edit);
             }
         }
         $table->id = 'Tabelle';
         $table->css = 'htmlobject_table';
         $table->border = 1;
         $table->cellspacing = 0;
         $table->cellpadding = 3;
         $table->autosort = false;
         $table->sort_link = false;
         $table->max = count($b);
         $table->head = $h;
         $table->body = $b;
         $table->form_action = $this->response->html->thisfile;
         $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100));
         $d['form'] = $this->response->get_form($this->actions_name, 'target', false)->get_elements();
         $d['table'] = $table;
     }
     return $d;
 }
 function remove()
 {
     $response = $this->get_response();
     $shelfs = $response->html->request()->get($this->identifier_name);
     $form = $response->form;
     if ($shelfs !== '') {
         require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
         $resource = new imageshelf();
         $submit = $form->get_elements('submit');
         $submit->handler = 'onclick="wait();"';
         $form->add($submit, 'submit');
         $submit = $form->get_elements('cancel');
         $submit->handler = 'onclick="cancel();"';
         $form->add($submit, 'cancel');
         $i = 0;
         foreach ($shelfs as $id) {
             $name = $resource->get_name($id);
             $d['param_f' . $i]['label'] = $name;
             $d['param_f' . $i]['object']['type'] = 'htmlobject_input';
             $d['param_f' . $i]['object']['attrib']['type'] = 'checkbox';
             $d['param_f' . $i]['object']['attrib']['name'] = $this->identifier_name . '[' . $i . ']';
             $d['param_f' . $i]['object']['attrib']['value'] = $id;
             $d['param_f' . $i]['object']['attrib']['checked'] = true;
             $i++;
         }
         $form->add($d);
         if (!$form->get_errors() && $response->submit()) {
             $imageshelf = new imageshelf();
             $errors = array();
             $message = array();
             foreach ($shelfs as $id) {
                 $imageshelf->get_instance_by_id($id);
                 $imageshelf->remove($id);
                 $form->remove($this->identifier_name . '[' . $id . ']');
                 $message[] = sprintf($this->lang['msg'], $imageshelf->name);
             }
             if (count($errors) === 0) {
                 $response->msg = join('<br>', $message);
             } else {
                 $msg = array_merge($errors, $message);
                 $response->error = join('<br>', $msg);
             }
         }
     } else {
         $response->msg = '';
     }
     return $response;
 }
 function select()
 {
     $h = array();
     $h['imageshelf_id']['title'] = $this->lang['table_id'];
     $h['imageshelf_name']['title'] = $this->lang['table_name'];
     $h['imageshelf_protocol']['title'] = $this->lang['table_protocol'];
     $h['imageshelf_uri']['title'] = $this->lang['table_uri'];
     $h['edit']['title'] = '&#160;';
     $h['edit']['sortable'] = false;
     $params = $this->response->get_array($this->actions_name, 'select');
     $b = array();
     require_once $this->openqrm->get('basedir') . '/plugins/image-shelf/web/class/imageshelf.class.php';
     $resource = new imageshelf();
     $table = $this->response->html->tablebuilder('ishelf', $params);
     $table->offset = 0;
     $table->sort = 'imageshelf_id';
     $table->limit = 10;
     $table->order = 'ASC';
     $table->max = $resource->get_count('all');
     $table->init();
     $resources = $resource->display_overview($table->offset, $table->limit, $table->sort, $table->order);
     foreach ($resources as $k => $v) {
         $a = $this->response->html->a();
         $a->title = $this->lang['action_edit'];
         $a->label = $this->lang['action_edit'];
         $a->handler = 'onclick="wait();"';
         $a->css = 'edit';
         $a->href = $this->response->get_url($this->actions_name, "template") . '&imageshelf_id=' . $v["imageshelf_id"];
         $b[] = array('imageshelf_id' => $v["imageshelf_id"], 'imageshelf_name' => $v["imageshelf_name"], 'imageshelf_protocol' => $v["imageshelf_protocol"], 'imageshelf_uri' => $v["imageshelf_uri"], 'edit' => $a->get_string());
     }
     $add = $this->response->html->a();
     $add->title = $this->lang['action_add'];
     $add->label = $this->lang['action_add'];
     $add->handler = 'onclick="wait();"';
     $add->css = 'add';
     $add->href = $this->response->get_url($this->actions_name, "add");
     $table->id = 'Tabelle';
     $table->css = 'htmlobject_table';
     $table->border = 1;
     $table->cellspacing = 0;
     $table->cellpadding = 3;
     $table->autosort = false;
     $table->sort_link = false;
     $table->max = count($b);
     $table->head = $h;
     $table->body = $b;
     $table->actions_name = $this->actions_name;
     $table->actions = array(array('remove' => $this->lang['action_remove']));
     $table->identifier = 'imageshelf_id';
     $table->identifier_name = $this->identifier_name;
     $table->limit_select = array(array("value" => 10, "text" => 10), array("value" => 20, "text" => 20), array("value" => 30, "text" => 30), array("value" => 50, "text" => 50), array("value" => 100, "text" => 100));
     $d['table'] = $table;
     $d['form'] = $this->response->get_form($this->actions_name, 'select', false)->get_elements();
     $d['add'] = $add->get_string();
     return $d;
 }