Esempio n. 1
0
 private function init()
 {
     if ($this->json) {
         return;
     }
     $jsonString = $this->jsonFile->contents();
     $json = json_decode($jsonString, true);
     if (!$json) {
         throw new \RuntimeException('Unable to parse json');
     }
     $this->json = $json;
 }
Esempio n. 2
0
 /**
  * Get Uploaded File
  *
  * @param $key
  * @param null $default
  * @param null $validator
  * @return InputFile
  */
 static function file($key, $default = null, $validator = null)
 {
     if (!isset($_FILES[$key]) || $_FILES[$key]['error'] != UPLOAD_ERR_OK) {
         return self::processError($default);
     }
     $file = new InputFile($_FILES[$key]['tmp_name']);
     $file->setContentType($_FILES[$key]['type']);
     $file->setOriginalName($_FILES[$key]['name']);
     if ($validator instanceof Validator) {
         if ($validator->execute($file)) {
             return $file;
         } else {
             return self::processError($default);
         }
     } else {
         if (is_callable($validator)) {
             try {
                 if ($validator($file)) {
                     return $file;
                 } else {
                     return self::processError($default);
                 }
             } catch (Exception $e) {
                 throw ReactHttpException::internalError("Validator error");
             }
         }
     }
     return $file;
 }
 function __toString()
 {
     $this->_html_name = $this->_name . '[file]';
     if ($this->current_filename == '') {
         return parent::__toString();
     }
     $html = new HtmlHelper();
     $id = $this->getAttribute('id');
     $button = '<div id="editablebox_' . $id . '">' . $this->current_filename . ' ';
     $button .= $html->absoluteLink('[X]', 'javascript:void(0)', array('id' => 'delete_' . $id));
     $button .= $html->inlineJavascript('Phaxsi.Event.addEvent(document.getElementById("delete_' . $id . '"), "click", deleteFile.createDelegate(this, ["' . $id . '", "' . $this->input_hidden->getAttribute('id') . '"]));');
     $button .= '</div>';
     $this->beforeHTML = $html->javascript('/widgets/custom/editablefile.js') . $button . $this->input_hidden->__toString();
     return parent::__toString();
 }
Esempio n. 4
0
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see 
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $input = parent::render($name, $value, $attributes, $errors);
     if (!$this->getOption('edit_mode')) {
         return $input;
     }
     if ($this->getOption('with_delete')) {
         $deleteName = ']' == substr($name, -1) ? substr($name, 0, -1) . '_delete]' : $name . '_delete';
         $delete = $this->renderTag('input', array_merge(array('type' => 'checkbox', 'name' => $deleteName), $attributes));
         $deleteLabel = $this->translate($this->getOption('delete_label'));
         $deleteLabel = $this->renderContentTag('label', $deleteLabel, array_merge(array('for' => $this->generateId($deleteName))));
     } else {
         $delete = '';
         $deleteLabel = '';
     }
     return strtr($this->getOption('template'), array('%input%' => $input, '%delete%' => $delete, '%delete_label%' => $deleteLabel, '%file%' => $this->getFileAsTag($attributes)));
 }
Esempio n. 5
0
 public static function Factory($name, $label = '', $required = false, $attrList = array())
 {
     $element = new InputFile($name);
     $element->setLabel($label);
     $element->setRequired($required);
     $element->setOptionList($attrList);
     return $element;
 }
    public function p()
    {
        $t = time();
        $if = new \InputFileModel();
        ?>
		<div id="input_file_img_<?php 
        echo $t;
        ?>
"
		     <?php 
        if (!self::isImage($this->value) || !self::isVideo($this->value)) {
            ?>
style="display: none;"<?php 
        }
        ?>
 >
			<?php 
        //if(self::isImage($this->value)){
        $src = InputFile::getFoto($this->value);
        echo $src;
        echo $this->value;
        $id = "holder_file_old_" . $t;
        echo $id;
        echo InputFile::makeFoto($src, $id);
        //}
        ?>
		</div>

		<input type="hidden"
		       name="<?php 
        echo $this->name;
        ?>
"
		       id="<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
"
		       value="<?php 
        echo $this->value;
        ?>
">



		<div id="hidupload_<?php 
        echo $t;
        ?>
">
			<input type="file"
			       id="uploadfolder_<?php 
        echo $t;
        ?>
"
			       name="upload" />
			<i class="glyphicon glyphicon-ok"
			   id="file_ok_<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
"
			   style="display: none;"></i>
			<i class="glyphicon glyphicon-repeat"
			   id="file_repeat_<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
"
			   style="display: none;"></i>
		</div>
		<script type="text/javascript">

			// Variable to store your files
			var files;

			// Add events
			$('#hidupload_<?php 
        echo $t;
        ?>
 input[type=file]').on('change', inputFiles_<?php 
        echo $t;
        ?>
);

			// Grab the files and set them to our variable
			/*function prepareUpload(event)
			 {
			 files = event.target.files;
			 } */
			// Catch the form submit and upload the files
			function inputFiles_<?php 
        echo $t;
        ?>
(event) {
				files = event.target.files;
				event.stopPropagation(); // Stop stuff happening
				event.preventDefault(); // Totally stop stuff happening

				// START A LOADING SPINNER HERE

				// Create a formdata object and add the files
				var data = new FormData();
				$.each(files, function (key, value) {
					data.append(key, value);
				});
				//console.log(data);
				$.ajax({
					url: '<?php 
        echo _SPPATH;
        ?>
Uploader/uploadfiles?t=<?php 
        echo $t;
        ?>
&files=1&adafile=<?php 
        echo $this->value;
        ?>
',
					type: 'POST',
					data: data,
					cache: false,
					dataType: 'json',
					processData: false, // Don't process the files
					contentType: false, // Set content type to false as jQuery will tell the server its a query string request
					success: function (data, textStatus, jqXHR) {
						// console.log(data);

						if (data.bool) {
							// Success so call function to process the form
							//submitForm(event, data);
							console.log("success");
							// loadfolder_<?php 
        echo $t;
        ?>
(activeTID_<?php 
        echo $t;
        ?>
);
							$("#file_ok_<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
").show();
							//var slc = $('#uploadfolder_<?php 
        echo $t;
        ?>
').val();
							$("#<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
").val(data.filename);
							if (data.isImage) {
								var imageHtml = document.getElementById("<?php 
        echo $id;
        ?>
");
								imageHtml.removeAttribute("style");
								imageHtml.removeAttribute("width");
								imageHtml.removeAttribute("height");
								imageHtml.src = '<?php 
        echo _SPPATH;
        echo $if->upload_url;
        ?>
' + data.filename;
								$("#input_file_img_<?php 
        echo $t;
        ?>
").show();
							} else {
								generateThumbnail(data.filename);
							}
						}
						else {
							// Handle errors here
							console.log('ERRORS: ' + data.error);
							$("#file_repeat_<?php 
        echo $this->id;
        ?>
_<?php 
        echo $t;
        ?>
").show();
						}
					},
					error: function (jqXHR, textStatus, errorThrown) {
						// Handle errors here
						console.log('ERRORS: ' + textStatus);
						// STOP LOADING SPINNER
					}
				});
			}

			function generateThumbnail(filename) {
				$.get("<?php 
        echo _SPPATH;
        ?>
Video/generateThumbnail?filename=" + filename,
					function (dataReturn) {
						console.log(dataReturn);

						var imageHtml = document.getElementById("<?php 
        echo $id;
        ?>
");
						imageHtml.removeAttribute("style");
						imageHtml.removeAttribute("width");
						imageHtml.removeAttribute("height");
						imageHtml.src = '<?php 
        echo _SPPATH;
        echo $if->upload_url;
        ?>
' + dataReturn;
						$("#input_file_img_<?php 
        echo $t;
        ?>
").show();
						$("#video_upload_preview").val(dataReturn);
					});
			}
		</script>
	<?php 
    }
 function getValue($filtered = true)
 {
     $value = parent::getValue($filtered);
     $this->_saved_thumbs = call_user_func_array(array(&$this, 'createThumbs'), $this->_thumbs_target);
     return $value;
 }
Esempio n. 8
0
            $input['warehouse_details'][] = array('warehouse_coord' => array(array('row' => $wh_coord_parts[0], 'col' => $wh_coord_parts[1])), 'warehouse_product_count' => $wh_product_count_parts);
        }
        //orders
        $input['orders'] = fgets($file);
        $input['order_details'] = array();
        for ($i = 0; $i < $input['orders']; $i++) {
            $order_coord_parts = Self::splitstring(fgets($file));
            $item_count = fgets($file);
            $product_types = Self::splitstring(fgets($file));
            $input['order_details'][] = array('delivery_coord' => array(array('row' => $order_coord_parts[0], 'col' => $order_coord_parts[1])), 'item_count' => $item_count, 'product_types' => $product_types, 'order_weight' => Self::getTotalWeight($product_types, $input['product_weights']));
        }
        fclose($file);
        return $input;
    }
}
$structure = InputFile::fromFile('./cases/busy_day.in');
//var_dump(json_encode($structure));
$all_orders = $structure['order_details'];
$one_trip_orders = array();
$order_id = 0;
foreach ($all_orders as $single_order) {
    if ($single_order['order_weight'] <= $structure['maxload']) {
        $one_trip_orders[] = array('order_id' => $order_id, 'order' => $single_order);
    }
    ++$order_id;
}
//echo count($one_trip_orders), '/', count($all_orders);
//var_dump(json_encode($one_trip_orders));
//var_dump(json_encode($structure['warehouse_details']));
$current_drone_id = 0;
foreach ($one_trip_orders as $single_order) {
Esempio n. 9
0
 /**
  *
  */
 public function testConstruct()
 {
     $entity = new InputFile("testdata");
     $this->assertEquals("testdata", $entity->getFileContents());
     $this->assertEquals("testdata", (string) $entity);
 }