summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorBjörn Geiger2011-09-08 13:45:49 +0200
committerBjörn Geiger2011-09-08 13:45:49 +0200
commiteb21e13dcdd038315d0ad1ff4941d1069af9b977 (patch)
treef01bcd0cc3e5efa56cec23f650582f6d33af8481 /library
parentsome changes (diff)
downloadpoolctrl-eb21e13dcdd038315d0ad1ff4941d1069af9b977.tar.gz
poolctrl-eb21e13dcdd038315d0ad1ff4941d1069af9b977.tar.xz
poolctrl-eb21e13dcdd038315d0ad1ff4941d1069af9b977.zip
kleine korrekturen
Diffstat (limited to 'library')
-rw-r--r--library/Poolctrl/Functions.php64
-rw-r--r--library/Poolctrl/Validator/DateGreaterThan.php71
2 files changed, 135 insertions, 0 deletions
diff --git a/library/Poolctrl/Functions.php b/library/Poolctrl/Functions.php
new file mode 100644
index 0000000..0b89390
--- /dev/null
+++ b/library/Poolctrl/Functions.php
@@ -0,0 +1,64 @@
+<?php
+/*
+ * Copyright (c) 2011 - OpenSLX GmbH, RZ Uni Freiburg
+ * This program is free software distributed under the GPL version 2.
+ * See http://gpl.openslx.org/
+ *
+ * If you have any feedback please consult http://feedback.openslx.org/ and
+ * send your suggestions, praise, or complaints to feedback@openslx.org
+ *
+ * General information about OpenSLX can be found at http://openslx.org/
+ */
+function randomString($name_laenge = 16) {
+ $zeichen = "abcedfghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZ0123456789";
+ $name_neu = "";
+
+ mt_srand ((double) microtime() * 1000000);
+ for ($i = 0; $i < $name_laenge; $i++ ) {
+ $name_neu .= $zeichen{mt_rand (0,strlen($zeichen) - 1)};
+ }
+ return $name_neu;
+}
+
+function print_a(){
+ $numargs = func_num_args();
+ if($numargs>1){
+ $out = '';
+ ob_start();
+ echo "<div style='background-color:#FFCC33;border:1px solid black;margin:3px;padding:5px;'>";
+ for($a=0;$a<$numargs;$a++)
+ print_a(func_get_arg($a));
+ echo "</div>";
+ $out .= ob_get_contents();
+ ob_end_clean();
+ echo $out;
+ }else{
+ echo "<pre style='background-color:#FFDF80;border:1px solid #000;margin:3px;padding:5px;'>";
+ $a = func_get_arg(0);
+ $a = (is_bool($a))?(($a)?'true':'false'):$a;
+ print_r($a);
+ echo "</pre>";
+ }
+}
+
+function PostToHost($host, $path, $referer, $userAgent, $dataToSend) {
+ $fp = @ fsockopen($host, 80);
+ @ fputs($fp, "POST $path HTTP/1.1\r\n");
+ @ fputs($fp, "Host: $host\r\n");
+ @ fputs($fp, "User-Agent: $userAgent\r\n");
+ @ fputs($fp, "Referer: $referer\r\n");
+ @ fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
+ @ fputs($fp, "Content-length: ". strlen($dataToSend) ."\r\n");
+ @ fputs($fp, "Connection: close\r\n\r\n");
+ @ fputs($fp, $dataToSend);
+ $res = "";
+ while(!@ feof($fp)) {
+ $res .= @ fgets($fp, 128);
+ }
+ @ fclose($fp);
+
+ $res = @ explode("\r\n\r\n",$res);
+ $result['http-header'] = $res[0];
+ $result['http-body'] = $res[1];
+ return $result;
+} \ No newline at end of file
diff --git a/library/Poolctrl/Validator/DateGreaterThan.php b/library/Poolctrl/Validator/DateGreaterThan.php
new file mode 100644
index 0000000..f6c1316
--- /dev/null
+++ b/library/Poolctrl/Validator/DateGreaterThan.php
@@ -0,0 +1,71 @@
+<?php
+require_once 'Zend/Validate/Abstract.php';
+
+class Poolctrl_Validate_DateGreaterThan extends Zend_Validate_Abstract
+{
+ const NOT_GREATER = 'notGreaterThan';
+
+ protected $_messageTemplates = array(
+ self::NOT_GREATER => "'%value%' has to be greater than '%min%'",
+ );
+
+ protected $_messageVariables = array(
+ 'min' => '_min'
+ );
+
+ protected $_min;
+ protected $_minTimestamp;
+
+ public function __construct($min)
+ {
+ if ($min instanceof Zend_Config) {
+ $min = $min->toArray();
+ }
+
+ if (is_array($min)) {
+ if (array_key_exists('min', $min)) {
+ $min = $min['min'];
+ $minTimestamp = strtotime($min);
+ } else {
+ require_once 'Zend/Validate/Exception.php';
+ throw new Zend_Validate_Exception("Missing option 'min'");
+ }
+ }
+
+ $this->setMin($min);
+ $this->setMinTimestamp($minTimestamp);
+ }
+
+ public function getMin()
+ {
+ return $this->_min;
+ }
+
+ public function setMin($min)
+ {
+ $this->_min = $min;
+ return $this;
+ }
+
+ public function getMinTimestamp()
+ {
+ return $this->_minTimestamp;
+ }
+
+ public function setMinTimestamp($_minTimestamp)
+ {
+ $this->_minTimestamp = $_minTimestamp;
+ }
+
+ public function isValid($value)
+ {
+ $this->_setValue($value);
+ $valueTimestamp = strtotime($value);
+
+ if ($this->getMinTimestamp() >= $valueTimestamp) {
+ $this->_error(self::NOT_GREATER);
+ return false;
+ }
+ return true;
+ }
+} \ No newline at end of file