<?
class create
{//DigiHex Systems\\


	function init() {}


	function uniq() {
		$t=explode(' ',microtime());
		return $t[1].str_replace('0.','',$t[0]);
	}


	function random($chars=8, $lower=false) {
		if($chars<1) return false;
		for($i=1; $i<=$chars; $i++) {
			mt_srand((double)microtime()*1000000);
			$rand.=$this->assign_random_value(mt_rand(1,36));
		}
		if($lower==true) return $rand;
      return strtoupper($rand);
	}


	function assign_random_value($index) {
		switch($index) {
			case 1:  $v='a';  break;
			case 2:  $v='b';  break;
			case 3:  $v='c';  break;
			case 4:  $v='d';  break;
			case 5:  $v='e';  break;
			case 6:  $v='f';  break;
			case 7:  $v='g';  break;
			case 8:  $v='h';  break;
			case 9:  $v='i';  break;
			case 10: $v='j';  break;
			case 11: $v='k';  break;
 			case 12: $v='l';  break;
			case 13: $v='m';  break;
			case 14: $v='n';  break;
//			case 15: $v='o';  break;
			case 16: $v='p';  break;
			case 17: $v='q';  break;
			case 18: $v='r';  break;
			case 19: $v='s';  break;
			case 20: $v='t';  break;
			case 21: $v='u';  break;
			case 22: $v='v';  break;
			case 23: $v='w';  break;
			case 24: $v='x';  break;
			case 25: $v='y';  break;
			case 26: $v='z';  break;
			case 27: $v='0';  break;
			case 28: $v='1';  break;
			case 29: $v='2';  break;
			case 30: $v='3';  break;
			case 31: $v='4';  break;
			case 32: $v='5';  break;
			case 33: $v='6';  break;
			case 34: $v='7';  break;
			case 35: $v='8';  break;
			case 36: $v='9';  break;
			default: $v='X';	break;
		}
		return $v;
	}


	function next_date($ile_dni, $custom_date=false, $return_time=false) {
		if(!empty($custom_date)) {
			$date=explode('-',$custom_date);
			$rok=$date[0];
			$miesiac=$date[1];
         $dzien=$date[2];
		} else {
			$rok=date('Y');
			$miesiac=date('m');
         $dzien=date('d');
		}

		return date('Y-m-d'.($return_time==true ? ' H:i:s':''), mktime(date('H'),date('i'),date('s'),$miesiac,$dzien+$ile_dni,$rok));
	}


	function next_month($ile_mcy) {
		$dzien=date('d');
		$miesiac=date('m');
		$rok=date('Y');

		$next_date=mktime(date('H'),date('i'),date('s'),$miesiac+$ile_mcy,$dzien,$rok);
		return date("Y-m-d", $next_date);
	}


	function next_year($ile_lat) {
		$dzien=date('d');
		$miesiac=date('m');
		$rok=date('Y');

		$next_date=mktime(date('H'),date('i'),date('s'),$miesiac,$dzien,$rok+$ile_lat);
		return date("Y-m-d", $next_date);
	}


	function next_robocze($workDays, $date1=false, $negative=false) {
		$NOW=date('Y-m-d H:i:s');
		if(empty($date1)) $date1=$NOW;
		$workDays=(int)$workDays;
		if($workDays<=0) return $NOW;
		$date1=strtotime(($negative==true ? '+':'-').'1 day',strtotime($date1));
		$WOLNE=array('01-01','01-06','05-01','05-03','08-15','11-01','11-11','12-25','12-26'); //mm-dd

	    $i=0;
	    while($i<=$workDays) {
			$date1=strtotime(($negative==true ? '-':'+').'1 day',$date1);
			$year=date('Y',$date1);

			if($year!=$lastYear) { //calc easter in given year
				$lastYear = $year;
				$easter = date('m-d', easter_date($year));
				$date = strtotime($year.'-'.$easter);
				$WOLNE[] = $easter;
				$WOLNE[] = date('m-d', strtotime('+1 day', $date));
				$WOLNE[] = date('m-d', strtotime('+60 days', $date));
			}
			$weekDay=date('w',$date1);

			if(!($weekDay==0 || $weekDay==6 || in_array(date('m-d',$date1),$WOLNE))) $i++;
		}

		return date('Y-m-d H:i:s',$date1);
	}


	function next_robocze_pl($dni) {
		if($dni==0) return 'dni roboczych';
		if($dni==1) return 'dzień roboczy';
		if($dni>=2 && $dni<=2) return 'dni robocze';
		if($dni>=5) return 'dni roboczych';
	}


}//DigiHex Systems\\
?>