<?php
// $Id: addevent.php,v 1.1 2004/07/11 10:27:50 Farsus Exp $
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: Nobse, Bama
// Author Website : http://www.e-xoops.de, http://service.bama-webdesign.de
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
    include("header.php");
    include("cache/config.php");
    
    if ($xoopsUser) {
	    $group = $xoopsUser->groups();
	}else{
	    $group[] = 3;
	}
	$anno = explode("|", $anoevent);
	$is = array_intersect ($group, $anno);
	if (count($is) > 0) {

        include(XOOPS_ROOT_PATH."/header.php");
            $mytree = new XoopsTree($db->prefix('ecal_cat'), "cid", "pid");           
            global $xoopsUser, $db, $myts, $mytree;            
            $month = isset($monat) ? $monat : $month;
            $year = isset($jahr) ? $jahr : $year;
            $heure = isset($heure) ? $heure : 9;
            $minute = isset($minute) ? $minute : 0;
            $heureend = isset($heureend) ? $heureend : 19;
            $minuteend = isset($minuteend) ? $minuteend : 0;            
            echo "<script>
                      function verify() {
                            var msg = \""._CAL_VALIDERORMSG."\\n__________________________________________________\\n\\n\";
                            var errors = \"FALSE\";
                           	if (document.Add.username.value == \"0\") {
                                   errors = \"TRUE\";
                                   msg += \""._CAL_VALIDNAME."\\n\";
                            }
            				if (document.Add.subject.value == \"\") {
                                    errors = \"TRUE\";
                                    msg += \""._CAL_VALIDTITRE."\\n\";
                            }
            				if (document.Add.description1.value == \"\") {
                                    errors = \"TRUE\";
                                    msg += \""._CAL_VALIDDESC."\\n\";
                            }
            				if (errors == \"TRUE\") {
                                    msg += \"__________________________________________________\\n\\n"._CAL_VALIDMSG."\\n\";
                                    alert(msg);
                                    return false;
                            }
                      }
                      </script>";            
            If (!$month && !$lastday && !$year) {
            	if ($xoopsUser) {
					$useroffset = $xoopsUser->getVar("timezone_offset");
				} else {
					$useroffset = $xoopsConfig['default_TZ'];
				}

				$usertimevent = (time() + (($useroffset - ($xoopsConfig['server_TZ'] - date('I'))) * 3600));
                $day = date("j", $usertimevent);
                $month = date("m", $usertimevent);
                $year = date("Y", $usertimevent);
            }            
            $query1 = $db->query("SELECT lid, location FROM ".$db->prefix("ecal_location")." ORDER BY location ASC");
            OpenTable();
                $lastday = 1;
                while (checkdate($month,$lastday,$year)) {
                    $lastday++;
                }
        
        	if ($moderat == '1') {
        	    echo "<b>"._ADDN."</b><br><br><CENTER>"._CAL_YESMODERATE."</CENTER><br><br>";
        		} else {
        		echo "<b>"._ADDN."</b><br><br><CENTER>"._CAL_NOMODERATE."</CENTER><br><br>";
        	}
            //***************************************************************************
            echo "<center><form name='form1' method='post' action='addevent.php'>";
            echo _CAL_MONATH." <select class='select' name='monat'>";
            for ($xmonat=1; $xmonat<13; $xmonat++) {
            	if ($xmonat == $month) {
            		$sel = "selected";
        		} else {
        			$sel = "";
        		}
            	echo "<option value='$xmonat' $sel>$xmonat</option>";
            }echo "</select>&nbsp;";            
            echo _CAL_JAHR." <select class='select' name='jahr'>";
            $cyear    = date('Y');
            for ($xyear=($year); $xyear < ($cyear+5); $xyear++) {
            	if ($xyear == $year) {
            		$sel = "selected";
        		} else {
        			$sel = "";
        		}
        	echo "<option value='$xyear' $sel>$xyear</option>";
            }
            echo "</select>&nbsp";
            echo "<input type='image' src='".XOOPS_URL."/modules/ecal/language/".$xoopsConfig['language']."/images/icon_selmonjahr_cal.gif'>";
            echo "</form>";	
            //**********************************************************************************            
            echo ""._CAL_SELECT."<P><form method='post' action='action.php' onSubmit=\"return verify();\" ENCTYPE=\"multipart/form-data\" NAME=\"Add\">";
            echo "<TABLE BORDER='0' CELLPADDING='0' CELLSPACING='5' align=\"center\"><TR><TD valign=\"top\" align=\"center\">";
            echo getMonthName($month); 
            echo " $year";
            littlecal($month,$year);
            echo "</TD></TR>";
    		$nextmonth = $month+1;
            $nextyear = $year;
            if ($nextmonth == 13) {
                    $nextmonth = 1;
                    $nextyear = $year + 1;
            }
    
            $lastmonth = $month-1;
            $lastyear = $year;
    
            if ($lastmonth == 0) {
                    $lastmonth = 12;
                    $lastyear = $year-1;
            }           
            echo "<tr><td colspan=\"2\"><center>";
            echo "<br>";
            echo "<a href='addevent.php?month=".$lastmonth."&year=".$lastyear."'><img src='".XOOPS_URL."/modules/ecal/images/".$lastmonth."l.gif'></a>";
            echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            echo "<a href='addevent.php?month=".$nextmonth."&year=".$nextyear."'><img src='".XOOPS_URL."/modules/ecal/images/".$nextmonth."r.gif'></a>";
            echo "</center></td></tr>";
            echo "</table><P>";
    		echo "<table border='0'>";
			echo "<tr><td colspan='2'><hr></td></tr>";
			echo "<tr><td><b>"._CAL_WIEDERHOLEN."</b></td><td><select class='select' name='wiederholen'>";
			if ($wiederholen == 0) {
			    $sel0 = " selected='selected'";
			}elseif ($wiederholen == 1){
				$sel1 = " selected='selected'";
			}elseif ($wiederholen == 2){
				$sel2 = " selected='selected'";
			}elseif ($wiederholen == 3){
				$sel3 = " selected='selected'";
			}elseif ($wiederholen == 4){
				$sel4 = " selected='selected'";
			}
			echo "<option value='0' ".$sel0." >"._CAL_WIEDERNEIN."</option>
				  <option value='1' ".$sel1." >"._CAL_WIEDEREINS."</option>
				  <option value='2' ".$sel2." >"._CAL_WIEDERZWEI."</option>
				  <option value='3' ".$sel3." >"._CAL_WIEDERDREI."</option>
				  <option value='4' ".$sel4." >"._CAL_WIEDERVIER."</option>		
				  </select></td></tr>";
			
			echo "<tr><td><b>"._CAL_WIEDERHOLENJEDEN."</b></td><td><select class='select' name='wiederholen1'>";
			if ($wiederholen1 == 0) {
			    $sel0 = " selected='selected'";
			}elseif ($wiederholen1 == 1){
				$sel1 = " selected='selected'";
			}elseif ($wiederholen1 == 2){
				$sel2 = " selected='selected'";
			}elseif ($wiederholen1 == 3){
				$sel3 = " selected='selected'";
			}elseif ($wiederholen1 == 4){
				$sel4 = " selected='selected'";
			}elseif ($wiederholen1 == 5){
				$sel5 = " selected='selected'";
			}
			echo "<option value='0' ".$sel0." >"._CAL_WIEDERNEIN."</option>
				  <option value='1' ".$sel1." >"._CAL_WIEDERERSTE."</option>
				  <option value='2' ".$sel2." >"._CAL_WIEDERZWEITE."</option>
				  <option value='3' ".$sel3." >"._CAL_WIEDERDRITTE."</option>
				  <option value='4' ".$sel4." >"._CAL_WIEDERVIERTE."</option>
				  <option value='5' ".$sel5." >"._CAL_WIEDERLETZTE."</option>			
				  </select></td></tr>";
			
			
			
			
			
			echo "<tr><td><b>"._CALWIEDERHOL."</b></td><td>";
			echo _D."<select class='select' name='wiedertag'>";
				for ($xday=1; $xday<32; $xday++) {
					if ($xday == $wiedertag) {
            			$sel = "selected";
        			} else {
        				$sel = "";
        			}
					echo "<option value='$xday' $sel>$xday</option>";
            	}
			echo "</select> ";
			echo _CAL_MONATH."<select class='select' name='wiedermonat'>";
				for ($xmonat=1; $xmonat<13; $xmonat++) {
					if ($xmonat == $wiedermonat) {
            			$sel = "selected";
        			} else {
        				$sel = "";
        			}
					echo "<option value='$xmonat' $sel>$xmonat</option>";
            	}
			echo "</select> ";
			echo _CAL_JAHR." <select class='select' name='wiederjahr'>";
            $cyear    = date('Y');
            for ($xyear=($year); $xyear < ($cyear+5); $xyear++) {
            	if ($xyear == $wiedermonat) {
            		$sel = "selected";
        		} else {
        			$sel = "";
        		}
        	echo "<option value='$xyear' $sel>$xyear</option>";
            }
            echo "</select></td></tr>";
			
			echo "<tr><td colspan='2'><hr></td></tr>";
			
			
    		if ( !$xoopsUser ) {
    			$calvisit=$xoopsConfig['anonymous'];
    			echo "<tr><td><b>"._USER."</b></td><td><input class='text' type='text' name='username' size='40'></td></tr>";
            } else {
    			$iddds =$xoopsUser->getVar("uname", "E");
    			$idmail =$xoopsUser->getVar("email", "E");
    		 	echo "<td><b>"._USER."</b></td><td>$iddds <input type='hidden' name='username' value='$iddds'></td></tr>";
            }
    
    		echo "<tr><td><b>"._CAL_CATEGORY."</b></td><td>";
    		echo $mytree->makeMySelBox("title", "title", $cid);
    		echo "</td></tr>";
    		
    		if (intval($locat_yn) == 1){
        		echo "<tr><td><b>"._CAL_LOCATION."</b></td><td>";
        		echo "<select class='select' name='locationid'>";
        		 while ($row = $db->fetch_array($query1)){
        			 if ($row[lid] == $locationid) {
        		        $sel = " selected='selected'";
        	        }
        			 echo "<option value='".$row[lid]."'".$sel.">".$row[location]."</option>";
        		 }
        		echo "</select>";
                if (intval($user_locyn) == 1){
                    echo "&nbsp;&nbsp;";
                    echo "<a href='addlocation.php'><img src='".XOOPS_URL."/modules/ecal/language/".$xoopsConfig['language']."/images/icon_new_loc.gif''></a>";
                }
                echo "</td></tr>";
    		}
			if ($xoopsUser) {
				echo "<tr><td><b>"._CAL_PRIVAT1."</b></td><td>";
    			if ($privat == 0){$sel1 = " selected='selected'";}else{$sel2 = " selected='selected'";}
    			echo "<select class='select' name='privat'><option value='0' ".$sel1.">"._CAL_OFFEN."</option><option value='1'".$sel2.">"._CAL_PRIVAT."</option>";
    			echo "</select></td></tr>";    		
    		}
			$currentday = date("j", time());
    		echo "<tr><td><b>"._T."</b></td><td>";
    		echo "<select class='select' name='heure'><option value=''></option>";
            buildHourSelect($heure);
    		echo "</select>&nbsp;<select class='select' name='minute'><option value=''></option>";
            buildMinSelect($minute);
    		echo "</select></td></tr>";    
    		echo "<tr><td><b>"._CAL_END."</b></td><td>";
    		echo "<select class='select' name='heureend'><option value=''></option>";
            buildHourSelect($heureend);
    		echo "</select>&nbsp;<select class='select' name='minuteend'><option value=''></option>";
            buildMinSelect($minuteend);
    		echo "</select></td></tr>";    		
    		$chk1 = ''; $chk0 = '';
    		$high == 1 ? $chk1 = " checked='checked'" : $chk0 = " checked='checked'";
    		echo "<tr><td><b>"._CAL_HIGH."</td><td>";
    		echo "<input type='radio' class='radio' name='high' value='1' '$chk1' />"._YES."";
    		echo "<input type='radio' class='radio' name='high' value='0' '$chk0' />"._NO."</td></tr>";    
    		echo "<tr><td><b>"._SUB."</b></td><td><input class='text' type='text' name='subject' MAXLENGTH='50'  size='40' value='".$subject."'></td></tr>";    		
    		echo "<tr><td><b>"._DESC2."</b></td><td>";
    		$desc = new XoopsFormDhtmlTextArea('', 'description1', $description1, 10, 50);
    		echo $desc->render();
    		echo "</td></tr>";
    		echo "<tr><td><b>"._CAL_BILDURL."</b></td><td><input class='text' type='text' name='flayer' size='40' value='".$flayer."'></td></tr>";
    		echo "</table>";    
    		if ($moderat == '1') {
    		    echo "<input type=hidden name=valid value=\"no\">";
    		} else {
    		    echo "<input type=hidden name=valid value=\"yes\">";
    		}   
    		echo "<input type='hidden' name='month' value='$month'>
    					<input type='hidden' name='year' value='$year'>
    					<input type='hidden' name='pa' value='AddEvent'>
    					<br><input type='image' src='".XOOPS_URL."/modules/ecal/language/".$xoopsConfig['language']."/images/icon_addevent.gif'>
    					</form><br>";
    		form_ret_ecal($month, $year);
            CloseTable();
            include(XOOPS_ROOT_PATH."/footer.php");
//        }
    }else{
        redirect_header("index.php", 3, _NO_AUTHORIZ);
    }
?>	