Exemplo n.º 1
0
 public function action_upload()
 {
     $out = array('status' => 'no');
     $val = \Validation::forge();
     $val->add_field('key2', 'Element id', 'required|min_length[1]|max_length[20]');
     $val->add_field('key1', 'Device id', 'required|min_length[1]|max_length[20]');
     $val->add_field('key3', 'Template or device', 'required|min_length[1]|max_length[20]');
     if ($val->run()) {
         $uploaddir = DOCROOT . 'images/uploads/';
         $name = basename($_FILES['image']['name']);
         $uploadfile = $uploaddir . $name;
         if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) {
             if ($val->validated('key3') != 'true') {
                 $this->tmpl = false;
                 $element = Model_Device_Fieldset::find($val->validated('key2'));
             } else {
                 $this->tmpl = true;
                 $element = Model_Device_Template_Field::find($val->validated('key2'));
             }
             if ($element) {
                 $imageOnHdd = \Image::forge()->load($uploadfile);
                 $sizes = $imageOnHdd->sizes();
                 //add new image in database
                 $props = array('name' => $name, 'elementID' => $element->id, 'type' => $this->sizeType($sizes), 'width' => 0, 'height' => 0);
                 if ($this->tmpl) {
                     $img = new Model_Device_Template_Image($props);
                     $prefix = 'temp';
                 } else {
                     $prefix = '';
                     $img = new Model_Image($props);
                 }
                 $new_width = $sizes->width >= 1000 ? 1000 : $sizes->width;
                 $new_height = $sizes->height >= 750 ? 750 : $sizes->height;
                 //resize original image 1000x1000px to folder > public/images
                 //make thumb 135x135px to folder public/images/thumb
                 if ($img->save()) {
                     $imageOnHdd->resize($new_width, $new_height, true, false)->save(DOCROOT . 'images/' . $prefix . $img->id . '.png')->config('quality', 70)->crop_resize(85, 85, true, false)->save(DOCROOT . 'images/tumb/' . $prefix . $img->id . '.png');
                     $resized = \Image::forge()->load(DOCROOT . 'images/' . $prefix . $img->id . '.png')->sizes();
                     $img->width = $resized->width;
                     $img->height = $resized->height;
                     $img->save();
                     unlink($uploadfile);
                     $out = array('id' => $img->id, 'type' => $img->type, 'status' => 'ok', 'h' => $img->height, 'w' => $img->width);
                 }
             }
         }
     }
     echo json_encode($out);
 }
Exemplo n.º 2
0
 public function before()
 {
     parent::before();
     if ($_POST) {
         $val = \Validation::forge('power');
         $val->add_field('eid', 'template id', 'required|min_length[1]|max_length[20]');
         $val->add_field('tmpl', 'template or realdevice', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             if ($val->validated('tmpl') == "true") {
                 $this->tmpl = true;
                 $this->field = Model_Device_Template_Field::find($val->validated('eid'));
                 //$this->TempsetTypeOfDevice();
             } else {
                 $this->tmpl = false;
                 $this->field = Model_Device_Fieldset::find($val->validated('eid'));
                 //$this->setTypeOfDevice();
             }
         }
     }
 }
Exemplo n.º 3
0
 public function action_value()
 {
     $val = \Validation::forge();
     $val->add_field('eid', 'Device element id', 'required|min_length[1]|max_length[25]');
     $val->add_field('val', 'Device element val', 'min_length[0]');
     if ($val->run()) {
         $field = Model_Device_Template_Field::find($val->validated('eid'));
         if ($field) {
             $field->value = $val->validated('val');
             $field->save();
             echo json_encode(array('status' => 'ok'));
         }
     }
 }
Exemplo n.º 4
0
 public function action_raid($id = null)
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('eid', 'Device fieldset id', 'required|min_length[1]|max_length[20]');
         $val->add_field('tmp', 'Device or template', 'required|min_length[1]|max_length[20]');
         //get raid table data
         if ($id == 'get') {
             if ($val->run()) {
                 if ($val->validated('tmp') == 'true') {
                     $field = Model_Device_Template_Field::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
                 } else {
                     $field = Model_Device_Fieldset::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('fieldsetID', $field->id)->get_one();
                 }
                 $data['eid'] = $field->id;
                 $data['raid'] = $raid;
                 return \Response::forge(\View::forge('device/raid', $data));
             }
         }
         //change type
         if ($id == 'type') {
             $val->add_field('type', 'Raid new type', 'required|min_length[1]|max_length[3]');
             if ($val->run()) {
                 if ($val->validated('tmp') == 'true') {
                     $field = Model_Device_Template_Field::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
                 } else {
                     $field = Model_Device_Fieldset::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('fieldsetID', $field->id)->get_one();
                 }
                 $new_type = $val->validated('type');
                 if ($new_type > 1) {
                     $raid_type = Model_Raid_Type::find($new_type);
                     $field->value = $raid_type['name'] . ', discs:' . $raid->size . ', cap:' . $raid->total . ' GB';
                 } else {
                     $field->value = 'Raid:none, discs:' . $raid->size . ', cap:' . $raid->total . ' GB';
                 }
                 $field->save();
                 $raid->raid_type = $new_type;
                 $raid->save();
             }
             $data['eid'] = $field->id;
             $data['raid'] = $raid;
             return \Response::forge(\View::forge('device/raid', $data));
         }
         //change total capacity
         if ($id == 'total') {
             $val->add_field('total', 'Raid total', 'required|min_length[1]|max_length[300]');
             if ($val->run()) {
                 if ($val->validated('tmp') == 'true') {
                     $field = Model_Device_Template_Field::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
                 } else {
                     $field = Model_Device_Fieldset::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('fieldsetID', $field->id)->get_one();
                 }
                 $total = $val->validated('total');
                 $raid_type = 'none';
                 if ($raid->raid_type > 0) {
                     $rt = Model_Raid_Type::find($raid->raid_type);
                     $raid_type = $rt->name;
                 }
                 $field->value = $raid_type . ', discs:' . $raid->size . ', cap:' . $total . ' GB';
                 $field->save();
                 $raid->total = $total;
                 $raid->save();
             }
             $data['eid'] = $field->id;
             $data['raid'] = $raid;
             return \Response::forge(\View::forge('device/raid', $data));
         }
         //change size
         if ($id == 'size') {
             $val->add_field('size', 'Raid new size', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 if ($val->validated('tmp') == 'true') {
                     $field = Model_Device_Template_Field::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
                 } else {
                     $field = Model_Device_Fieldset::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('fieldsetID', $field->id)->get_one();
                 }
                 $new_size = $val->validated('size');
                 $total = Model_Raid_Data::find()->where('hardware_raid', $raid->id)->count();
                 if ($new_size > 50) {
                     $new_size = 50;
                 }
                 $raid->size = $new_size;
                 $raid->save();
                 if ($new_size < $total) {
                     $dif = $total - $new_size;
                 } else {
                     $dif = $new_size - $total;
                 }
                 if ($total > $new_size) {
                     //delete overage fileds
                     $raid_data = Model_Raid_Data::find()->where('hardware_raid', $raid->id)->limit($dif)->order_by('id', 'desc')->get();
                     foreach ($raid_data as $dd) {
                         $dd->delete();
                     }
                 } else {
                     //add new empty fields (diference)
                     if ($total < $new_size) {
                         for ($i = 0; $i < $dif; $i++) {
                             $prop = array('hardware_raid' => $raid->id, 'model' => '', 'size' => '', 'vport' => '', 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'serial_number' => '');
                             $hdata = new Model_Raid_Data($prop);
                             $hdata->save();
                         }
                     }
                 }
                 $sum = 0;
                 $raid_type = Model_Raid_Type::find($raid->raid_type);
                 // sum raid
                 $raid_data = Model_Raid_Data::find()->where('hardware_raid', $raid->id)->order_by('id', 'desc')->get();
                 foreach ($raid_data as $dd) {
                     $sum += $dd->size;
                 }
                 if ($raid->raid_type > 0) {
                     $field->value = $raid_type['name'] . ', discs:' . $new_size . ', cap:' . $sum . ' GB';
                 } else {
                     $field->value = 'Raid:none, discs:' . $new_size . ', cap:' . $sum . ' GB';
                 }
                 $field->save();
                 $data['eid'] = $field->id;
                 $data['raid'] = $raid;
                 return \Response::forge(\View::forge('device/raid', $data));
             }
         }
         //set value of elements
         if ($id == 'set') {
             $val->add_field('rid', 'raid id', 'required|min_length[1]|max_length[5]');
             $val->add_field('type', ' number of input element', 'required|min_length[1]|max_length[5]');
             $val->add_field('val', 'data element id', 'required|min_length[0]|max_length[250]');
             if ($val->run()) {
                 $raid_data = Model_Raid_Data::find($val->validated('rid'));
                 if ($raid_data) {
                     switch ($val->validated('type')) {
                         case 1:
                             $raid_data->vport = $val->validated('val');
                             break;
                         case 2:
                             $raid_data->size = $val->validated('val');
                             break;
                         case 3:
                             $raid_data->model = $val->validated('val');
                             break;
                         case 4:
                             $raid_data->serial_number = $val->validated('val');
                             break;
                         default:
                             echo 'nop';
                             break;
                     }
                     $raid_data->save();
                 }
             }
         }
         //new element
         if ($id == 'new') {
             $val->add_field('val', 'items to add', 'required|min_length[1]|max_length[250]');
             if ($val->run()) {
                 if ($val->validated('tmp') == 'true') {
                     $field = Model_Device_Template_Field::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('tempfieldID', $field->id)->get_one();
                 } else {
                     $field = Model_Device_Fieldset::find($val->validated('eid'));
                     $raid = Model_Raid::find()->where('fieldsetID', $field->id)->get_one();
                 }
                 $new_size = $val->validated('val');
                 if ($raid->raid_type > 1) {
                     $raid_type = Model_Raid_Type::find($raid->raid_type);
                     $field->value = $raid_type['name'] . ', discs:' . $new_size . ', cap:' . $raid->total . ' GB';
                 } else {
                     $field->value = 'Raid:none, discs:' . $new_size . ', cap:' . $raid->total . ' GB';
                 }
                 $field->save();
                 $total = Model_Raid_Data::find()->where('hardware_raid', $raid->id)->count();
                 if ($new_size > 50) {
                     $new_size = 50;
                 }
                 $raid->size = $new_size;
                 $raid->save();
                 if ($new_size < $total) {
                     $dif = $total - $new_size;
                 } else {
                     $dif = $new_size - $total;
                 }
                 if ($total > $new_size) {
                     //delete overage fileds
                     $raid_data = Model_Raid_Data::find()->where('hardware_raid', $raid->id)->limit($dif)->order_by('id', 'desc')->get();
                     foreach ($raid_data as $dd) {
                         $dd->delete();
                     }
                 } else {
                     //add new empty fields (diference)
                     if ($total < $new_size) {
                         for ($i = 0; $i < $dif; $i++) {
                             $prop = array('hardware_raid' => $raid->id, 'model' => \Input::post('dmodel'), 'size' => \Input::post('dsize'), 'vport' => \Input::post('vport'), 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'serial_number' => \Input::post('dsn'));
                             $hdata = new Model_Raid_Data($prop);
                             $hdata->save();
                         }
                     }
                 }
                 $data['eid'] = $field->id;
                 $data['raid'] = $raid;
                 return \Response::forge(\View::forge('device/raid', $data));
             }
         }
         //delete element
         if ($id == 'delete') {
             $val->add_field('rid', 'data element id', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 $raid_data = Model_Raid_Data::find($val->validated('rid'));
                 $raid_data->delete();
                 echo json_encode(array('deleted' => 1));
             }
         }
     }
 }
Exemplo n.º 5
0
 public function action_element($id = null)
 {
     if ($_POST) {
         $val = \Validation::forge('templates');
         //$val->add_field('stid', 'template id', 'required|min_length[1]|max_length[20]');
         if ($id == 'rename') {
             $val->add_field('fid', 'fieldset id', 'required|min_length[1]|max_length[20]');
             $val->add_field('name', 'fieldset new name', 'required|min_length[1]|max_length[250]');
             if ($val->run()) {
                 $field = Model_Device_Template_Field::find($val->validated('fid'));
                 $status = false;
                 if ($field) {
                     $field->name = $val->validated('name');
                     $status = $field->save();
                 }
                 $a = array('status' => $status);
                 echo json_encode($a);
             }
         }
         if ($id == 'remove') {
             $val->add_field('fid', 'fieldset id', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 $field = Model_Device_Template_Field::find($val->validated('fid'));
                 $status = $field->delete();
                 $a = array('status' => $status);
                 echo json_encode($a);
             }
         }
         if ($id == 'new') {
             $val->add_field('tid', 'template id', 'required|min_length[1]|max_length[20]');
             $val->add_field('name', 'element name', 'required|min_length[1]|max_length[250]');
             $val->add_field('type', 'element type', 'required|min_length[1]|max_length[20]');
             $val->add_field('tab', 'window tab', 'required|min_length[1]|max_length[20]');
             if ($val->run()) {
                 $template = Model_Device_Template::find($val->validated('tid'));
                 $temp_field_props = array('name' => $val->validated('name'), 'type' => $this->elements($val->validated('type')), 'static' => 0, 'templateID' => $template->id, 'tab' => $val->validated('tab'));
                 $template_field = new Model_Device_Template_Field($temp_field_props);
                 $template_field->save();
                 $a = array('id' => $template_field->id);
                 echo json_encode($a);
             }
         }
     }
 }