Exemplo n.º 1
0
 public function action_new()
 {
     $a = array('stat' => 'no');
     if ($_POST) {
         $this->val->add_field('tid', 'template id', 'required|min_length[1]|max_length[20]');
         $this->val->add_field('name', 'element name', 'required|min_length[1]|max_length[250]');
         $this->val->add_field('type', 'element type', 'required|min_length[1]|max_length[20]');
         $this->val->add_field('tab', 'window tab', 'required|min_length[1]|max_length[20]');
         if ($this->val->run()) {
             $device = Model_Device::find($this->val->validated('tid'));
             if ($device) {
                 $field_props = array('type' => $this->elements($this->val->validated('type')), 'name' => $this->val->validated('name'), 'static' => 0, 'deviceID' => $device->id, 'tab' => $this->val->validated('tab'));
                 $field = new Model_Device_Fieldset($field_props);
                 $field->save();
                 $a = array('id' => $field->id);
             }
         }
     }
     echo json_encode($a);
 }
Exemplo n.º 2
0
 private function insertStaticField($name, $type, $tab, $device, $static)
 {
     $field = new Model_Device_Fieldset();
     $field->name = $name;
     $field->type = $type[0];
     $field->static = $static;
     $field->deviceID = $device->id;
     $field->tab = $tab;
     if ($type[1] != null) {
         $field->extra = $type[1];
     }
     if ($type[2] != null) {
         $field->value = $type[2];
     }
     $field->save();
     if ($type == 'network') {
         $prop = array('fieldsetID' => $field->id, 'deviceID' => $field->device->id, 'nics' => 0, 'vports' => 0, 'ports' => 0, 'uplinks' => 0, 'config_data' => '', 'type' => $this->net_type);
         $network = new Model_Device_Network($prop);
         //$network->save();
     }
     return true;
 }
Exemplo n.º 3
0
 protected function insertStaticField($name, $type, $tab, $device, $static)
 {
     $field = new Model_Device_Fieldset();
     $field->name = $name;
     $field->type = $type[0];
     $field->static = $static;
     $field->deviceID = $device->id;
     $field->tab = $tab;
     if ($type[1] != null) {
         $field->extra = $type[1];
     }
     if ($type[2] != null) {
         $field->value = $type[2];
     }
     $field->save();
 }
Exemplo n.º 4
0
 public function insertStaticField($name, $type, $tab, $device, $static)
 {
     $field = new Model_Device_Fieldset();
     $field->name = $name;
     $field->type = $type;
     $field->static = $static;
     $field->deviceID = $device->id;
     $field->tab = $tab;
     $field->save();
 }
Exemplo n.º 5
0
 public function action_device($id = null)
 {
     if ($_POST) {
         $val = \Validation::forge('templates');
         if ($id == 'edit') {
             $val->add_field('did', 'device id', 'required|min_length[1]|max_length[20]');
             $val->add_field('type', 'device new type', 'required|min_length[1]|max_length[10]');
             if ($val->run()) {
                 //get device current template type
                 $dev = Model_Device::find($val->validated('did'));
                 //set template
                 $template = Model_Device_Template::find($val->validated('type'));
                 //category
                 $cat = $template->category;
                 //store position of vertical pdu
                 $power_temp = false;
                 if ($cat->id == 4) {
                     if ($dev->meta_default_data > 0) {
                         $power_temp = $dev->power;
                     }
                 }
                 $pdu_size_wrong = $this->check_for_PDU($template, $dev);
                 if ($pdu_size_wrong) {
                     echo json_encode(array('error' => 'You cant use this template, no enough space in rack'));
                 } else {
                     $dev_fields = Model_Device_Fieldset::find()->where('deviceID', $dev->id)->get();
                     //delete all data from device
                     foreach ($dev_fields as $dev_field) {
                         $dev_field->delete();
                     }
                     $fields = $template->field;
                     $dev->type = $template->id;
                     $dev->save();
                     foreach ($fields as $field) {
                         $data = array('name' => $field['name'], 'static' => $field['static'], 'value' => htmlspecialchars_decode($field['value']), 'type' => $field['type'], 'deviceID' => $dev->id, 'tab' => $field['tab'], 'extra' => $field['extra']);
                         $new_field = new Model_Device_Fieldset($data);
                         $new_field->save();
                         $this->insert_template_to_device_data($field, $new_field);
                     }
                     $out = false;
                     if ($cat->id == 4) {
                         $dev = Model_Device::find($val->validated('did'));
                         //check if vertical PDU , and echo number of output pins
                         if ($dev->meta_default_data > 0) {
                             $po = Model_Device_Power::find()->where('deviceID', $val->validated('did'))->get_one();
                             $po->pos = $power_temp->pos;
                             $po->ru = $power_temp->ru;
                             $po->save();
                             $out = $po->output;
                             echo json_encode(array('type' => $template->id, 'id' => $dev->id, 'cat' => $cat->id, 'out' => $out));
                         }
                     }
                     if (!$out) {
                         echo json_encode(array('type' => $template->id, 'id' => $dev->id, 'cat' => $cat->id));
                     }
                 }
             }
         }
     }
 }