PHP - Restriction In Adding Events In Calendar
i want to share my problem in my website
For the better understandng of my website, I want to tell all the details. 1. I have a database and i has a 2 tables 1 for the tbllogin which consist of Username and Department, and the second table is caltbl which i use for the calendar events. 2.When my website run the first webpage is the login form. If the Username and Department is correct she can browse the other webpages, like the calendar event. 3. In the calendar event you can see the calendar and when you click the date theirs a link "new event" appear and if theirs no existing event theres a text saying "No Events", when you click the link you can add events. I want that theirs a specific person that can only add events for the restriction of adding events. I want to happen that if the user is xxx and her department is yyy the link shoud appear and she can add events. i want that only to her the link should be appear.. here is my code: <?php $host = "localhost"; $username = ""; $password = ""; $dbCnx = @mysql_connect($host, $username, $password) or die('Could not Connect to the database'); $dbName = 'dspi'; mysql_select_db($dbName); ?> <script> function goLastMonth(month, year){ // If the month is January, decrement the year if(month == 1){ --year; month = 13; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month-1)+'&year='+year; } //next function function goNextMonth(month, year){ // If the month is December, increment the year if(month == 12){ ++year; month = 0; } document.location.href = '<?=$_SERVER['PHP_SELF'];?>?month='+(month+1)+'&year='+year; } function remChars(txtControl, txtCount, intMaxLength) { if(txtControl.value.length > intMaxLength) txtControl.value = txtControl.value.substring(0, (intMaxLength-1)); else txtCount.value = intMaxLength - txtControl.value.length; } function checkFilled() { var filled = 0 var x = document.form1.calName.value; //x = x.replace(/^\s+/,""); // strip leading spaces if (x.length > 0) {filled ++} var y = document.form1.calDesc.value; //y = y.replace(/^s+/,""); // strip leading spaces if (y.length > 0) {filled ++} if (filled == 2) { document.getElementById("Submit").disabled = false; } else {document.getElementById("Submit").disabled = true} // in case a field is filled then erased } </script> <html> <body> <?php //$todaysDate = date("n/j/Y"); //echo $todaysDate; // Get values from query string $day = (isset($_GET["day"])) ? $_GET['day'] : ""; $month = (isset($_GET["month"])) ? $_GET['month'] : ""; $year = (isset($_GET["year"])) ? $_GET['year'] : ""; //comparaters for today's date //$todaysDate = date("n/j/Y"); //$sel = (isset($_GET["sel"])) ? $_GET['sel'] : ""; //$what = (isset($_GET["what"])) ? $_GET['what'] : ""; //$day = (!isset($day)) ? $day = date("j") : $day = ""; if(empty($day)){ $day = date("j"); } if(empty($month)){ $month = date("n"); } if(empty($year)){ $year = date("Y"); } //set up vars for calendar etc $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; //$numEventsThisMonth = 0; //$hasEvent = false; //$todaysEvents = ""; //run a selec statement to hi-light the days function hiLightEvt($eMonth,$eDay,$eYear){ //$tDayName = date("l"); $todaysDate = date("n/j/Y"); $dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; if($todaysDate == $dateToCompare){ //$aClass = '<span>' . $tDayName . '</span>'; $aClass='class="today"'; }else{ //$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; //echo $todaysDate; //return; $sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'"; //echo $sql; //return; $result = mysql_query($sql); while($row= mysql_fetch_array($result)){ if($row['eCount'] >=1){ $aClass = 'class="event"'; }elseif($row['eCount'] ==0){ $aClass ='class="normal"'; } } } return $aClass; } ?> <div id="Calendar_Event"> <table width="350" cellpadding="0" cellspacing="0"> <tr> <td width="50" colspan="1"> <input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);"> </td> <td width="250" colspan="5"> <span class="title" style="color:#FFFFFF"><?php echo $monthName . " " . $year; ?></span><br> </td> <td width="50" colspan="1" align="right"> <input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);"> </td> </tr> <tr> <th>M</td> <th>T</td> <th>W</td> <th>T</td> <th>F</td> <th>S</td> <th>S</td> </tr> <tr> <?php for($i = 1; $i < $numDays+1; $i++, $counter++){ $dateToCompare = $month . '/' . $i . '/' . $year; $timeStamp = strtotime("$year-$month-$i"); //echo $timeStamp . '<br/>'; if($i == 1){ // Workout when the first day of the month is $firstDay = date("N", $timeStamp); for($j = 1; $j < $firstDay; $j++, $counter++){ echo "<td> </td>"; } } if($counter % 7 == 0 ){ ?> </tr><tr> <?php } ?> <!--right here--><td width="50" <?=hiLightEvt($month,$i,$year);?>><a href="<?=$_SERVER['PHP_SELF'] . '?month='. $month . '&day=' . $i . '&year=' . $year;?>&v=1"><?=$i;?></a></td> <?php } ?> </table> </div> <div id="New_Event"> <?php if(isset($_GET['v'])){ if(isset($_POST['Submit'])){ $sql="insert into calTbl(calName,calDesc,calDate,calStamp) values('" . $_POST['calName'] ."','" . $_POST['calDesc'] . "','" . $_POST['calDate'] . "',now())"; mysql_query($sql); } $sql="select calName,calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'"; //echo $sql; //return; $result = mysql_query($sql); $numRows = mysql_num_rows($result); $check=mysql_query("SELECT * FROM tbllogin WHERE Username='rhoda.barrera@dunlop.ph' AND Department='MIS'"); if (mysql_num_rows($check)>0){ ?> <a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">Add Even</a><a href="<?=$_SERVER['PHP_SELF'];?>?month=<?=$_GET['month'] . '&day=' . $_GET['day'] . '&year=' . $_GET['year'];?>&v=1&f=true">t</a><?php }else{ echo 'You cannot Add New Event'; }?> </div> <div id="Cal_Event"> <?php if(isset($_GET['f'])){ include 'calForm.php'; } if($numRows == 0 ){ echo ''; }else{ //echo '<ul>'; echo '<h3>Event Listed</h3>'; while($row = mysql_fetch_array($result)){ ?> <h5><?=$row['calName'];?></h5> <?=$row['calDesc'];?><br/> Listed On: <?=$row['calStamp'];?> <?php } } } ?> </div> </body> </html> Similar TutorialsI am working on a small project, creating a calendar based booking system which includes the following features: 1) A color coded key for Booked days, Available, Partly Booked, Off Days 2) Clickable days which open up a form with available time slots 3) When time slots selected another form which allows the user to enter details about the event and then book the day
I am using php, sql to complete the project. I am aware that there are scripts available online but i want to do this from scratch.
Stuck On The code below is for a php calendar, above is what i need to achieve. Please can someone help me on how to complete this. <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); ?> <?php if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); ?> <?php $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <table width="400" border="5" align="center"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table width="100%" border="2" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"> <strong> <?php echo $monthNames[$cMonth-1].' '.$cYear; ?> </strong> </td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "<tr> "; if($i < $startday) echo "<td></td> "; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td> "; if(($i % 7) == 6 ) echo "</tr> "; } ?> </table> </td> </tr> </table> Good Evening, I have a working knowledge or HTML/CSS and right now I am learning/reading about PHP. Currently I am looking to build a website around an events calendar, let me explain more. A user would log onto the site, submit a form (with an event), this would then be added to a calendar as well a new page for the event details. The calendar would be fully visible to an visitor to the site. I would also like the ability to add a ticker on the homepage with the latest events added. How complicated is this to implement? And what are the basic requirements? I hope this makes sense. Thanks, Cain I am trying to populate my even calendar with, well, events that are stored in a mysql table. I came across the following code and modified the query to work in my case. The code used mysql_query(), but I am using mysqli_query(), and for some reason it gets to that point and dies, but mysqli_error() doesn't even run; I just get "Error1:" If I take out the query part and only build the calendar it work perfectly. Does mysqli_query() not work inside a for loop? This hit my database for every day of the month, is there a better way? I also thought about running a query to pull all results then doing array_filter() inside the for loop for each day. Does this even work? I can't seem to figure it out. Code: [Select] ..... for($list_day = '1'; $list_day <= $days_in_month; $list_day++) { if($list_day == $today && $month == $nowmonth && $year == $nowyear) { $calendar.= '<td class="calendar-day-today">'; } else { $calendar.= '<td class="calendar-day">'; } /* add in the day number */ $todaydate = $year.'-'.$month.'-'.$list_day; $calendar.= '<div class="day-number" onclick=window.location.href="viewday.php?name='.$_SESSION['username'].'&id='.$todaydate.'">'.$list_day.'</div>'; $y = 0; if(strlen($x) == '1') {$x = $y.$x; } /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $todaydate = $year.'-'.$month.'-'.$list_day; $query = "SELECT * FROM health WHERE '$todaydate' >= event_start AND '$todaydate' <= event_end"; $results = mysqli_query($dbc, $query) or die ('Error1: '.mysqli_error($dbc)); if (mysqli_num_rows($results) > '0') { while($row = mysqli_fetch_array($results)){ extract($row); ...... I am open to any other suggestions also. Thanks for the help! Does anybody know of a calendar script that can handle reoccurring events ? I want to make a calendar that shows the schedule of a teacher in a school. most classes are weekly but some are only once a month or held irregular. classes are 50 minuter or sometimes 30 minutes. Preferably I would like to set the start time and end time of a class with a precision of 10 minutes. The output should be a html page that shows the weekly schedule with the days as columns and the hours as rows. Anybody knows of something similar or something I could use as a starting point ? thanks anatak Anyone have info on a simple PHP script that can display a particular month where you can insert events such as a birthday or special event? Not looking for anything too complicated or fansy. thanks Might anyone know a good tutorial on how I might go about doing this? I found a simple calendar script that works perfectly but now I'm trying make it so I can save an event that has a start and end date that are different then each other for reoccurring to a database then have it display correctly on the calendar when I query the database. I have no clue if I'm even going about this the right way. I haven't even started diving in to if the event was to reoccur once a week or once a month, I'm just trying to get it so it displays on the start date then displays every day until the end date. Right now I take the current day, month, year that the calendar is looping on and check it against the event day, month, year. If the current calendar day is on or after the event start date then it returns true and if the current calendar day is on or before the event end date it returns true.... so then if it returns true on both then I give it the go ahead to display on that day. What I have is: if($current_date['year'] > $event_date['year']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['year'] == $event_date['year']) { if($current_date['month'] > $event_date['month']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['month'] == $event_date['month']) { if($current_date['day'] > $event_date['day']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['day'] == $event_date['day']) { $result = ($return == 'boolean') ? true : 'today'; } else if($current_date['day'] < $event_date['day']) { $result = false; } } else if($current_date['month'] < $event_date['month']) { $result = false; } } else if($current_date['year'] < $event_date['year']) { $result = false; } break; case 'end': if($current_date['year'] < $event_date['year']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['year'] == $event_date['year']) { if($current_date['month'] < $event_date['month']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['month'] == $event_date['month']) { if($current_date['day'] < $event_date['day']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['day'] == $event_date['day']) { $result = ($return == 'boolean') ? true : 'today'; } else if($current_date['day'] > $event_date['day']) { $result = false; } } else if($current_date['month'] > $event_date['month']) { $result = false; } } else if($current_date['year'] > $event_date['year']) { $result = false; } Not sure if I posted this in the right board: As I'm setting up a plugin to parse Google Calendar events, when they are set as All Day events, they "end" at midnight, which pushes them into the next day. So if an event is to run All Day Friday, Saturday, and Sunday, it actually shows the end date as Monday, since it's midnight. Any thoughts? Hi, at the moment, I am pulling events from my Google Calendar and showing them by calling the outputCalendarByDateRange() function below. Now would like to be able to update/Delete them <html> <head> <title>Gdata</title> </head> <body> <?php //session_start(); //ini_set('display_errors',1); //ini_set('display_startup_errors',1); //error_reporting (E_ALL); //DATES if(!isset($_REQUEST['from'])){ $newdateTimeStart = "01/01/2009"; } else { $newdateTimeStart = $_REQUEST['from']; } if(!isset($_REQUEST['to'])){ $newdateTimeEnd = "11/05/2011"; } else { $newdateTimeEnd = $_REQUEST['to']; } $startyear = substr($newdateTimeStart, 6, 4); $startmonth = substr($newdateTimeStart, 3, 2); $startday = substr($newdateTimeStart, 0, 2); $newdateTimeStart = $startyear.'-'.$startmonth.'-'.$startday; $endyear = substr($newdateTimeEnd, 6, 4); $endmonth = substr($newdateTimeEnd, 3, 2); $endday = substr($newdateTimeEnd, 0, 2); $newdateTimeEnd = $endyear.'-'.$endmonth.'-'.$endday; $dateStart = $newdateTimeStart; $dateEnd = $newdateTimeEnd; //between dates function outputCalendarByDateRange($client, $startDate='2007-05-01', $endDate='2007-08-01') { $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser('default'); $query->setVisibility('private'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setStartMin($startDate); $query->setStartMax($endDate); $eventFeed = $gdataCal->getCalendarEventFeed($query); echo "<ul>\n"; foreach ($eventFeed as $event) { echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n"; echo "\t\t<ul>\n"; foreach ($event->when as $when) { echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n"; } echo "\t\t</ul>\n"; echo "\t</li>\n"; } echo "</ul>\n"; } //Connect to google calendar //If you do not have access to the PHP.INI file on the remote server, you should use the following statement to set the path information for Zend framework $clientLibraryPath = 'libraries'; $oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath); // load ZEND classes require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Http_Client'); // connect to calendar service $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $user = "***"gmail.com"; //Insert your google username $pass = "***"; //Insert your Google password //$user = stripslashes($_POST['user']); //Insert your google username //$pass = stripslashes($_POST['pass']); //Insert your Google password $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); $gcal = new Zend_Gdata_Calendar($client); function createEvent ($client, Zend_GData_Calendar $gcal, $title = 'testing google calendar', $desc='this is great', $where = 'at work', $startDate = '2011-04-20', $startTime = '10:00', $endDate = '2011-04-20', $endTime = '11:00', $tzOffset = '+01') { $newEvent = $gcal->newEventEntry(); $newEvent->title = $gcal->newTitle($title); $newEvent->where = array($gcal->newWhere($where)); $newEvent->content = $gcal->newContent("$desc"); $when = $gcal->newWhen(); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; $newEvent->when = array($when); // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned $createdEvent = $gcal->insertEvent($newEvent); return $createdEvent->id->text; } echo outputCalendarByDateRange($client, "$dateStart", "$dateEnd"); ?> </body> </html> Hello ,
I am trying to display my planned events in calendar using full calendar json, jquery. But its not getting displayed, but its getting inserted. I am not very good at jquery or json. please somebody help me in this...
here is my code
in my calendar.php (display page)
<div class="span8"> <div class="w-box w-box-green"> <div class="w-box-header"></div> <div class="w-box-content"> <div id='calendar_json'></div> </div> <div class="w-box-footer"> <p class="f-text">JSON events fetched from a script</p> </div> </div> </div> </div>and in my calendar.js jsonEvents: function() { if($('#calendar_json').length) { $('#calendar_json').fullCalendar({ header: { left: 'month,agendaWeek,agendaDay', center: 'title', right: 'prev,next' }, buttonText: { prev: '<i class="icon-chevron-left icon-white cal_prev" />', next: '<i class="icon-chevron-right icon-white cal_next" />' }, editable: true, firstDay: 1, // 0 - Sunday, 1 - Monday events: "php_helpers/json-events.php", eventDrop: function(event, delta) { alert(event.title + ' was moved ' + delta + ' days\n' + '(should probably update your database)'); } }); }json-events.php include("connect.php"); $year = date('Y'); $month = date('m'); //$db=public_db_connect(); $year = date('Y'); $month = date('m'); $command = "SELECT * FROM planner"; $result = mysql_query($command) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { echo "hi"; //$start = date("D, j M Y G:i:s T", strtotime($row['start'])); //$end = date("D, j M Y G:i:s T", strtotime($row['end_time'])); $start = date("Y-m-d", strtotime($row['from_time'])); //$start = "$year-$month-20"; $myid = $row['plan_id']; $eventsArray['plan_id'] = (int)trim($myid); //$eventsArray['title'] = $row['title']; $title = $row['company']; //$title = $row['title']; //echo $title; $eventsArray['company'] = $title; $eventsArray['from_time'] = $start; $eventsArray['to_time'] = $start; $eventsArray['url'] = "edit_calendar.php?calendarid=".$row['plan_id']; // $eventsArray['end'] = $end; // $eventsArray['allDay'] = false; $events[] = $eventsArray; } echo json_encode($events); Hi, I want to check entered dates and times that a user selects against my "book-off" calendar which is a Google Calendar. The dates× from Google is in the form: 2011-04-29T23:00:00.000+02:00 The dates in my booking software (ABPro) is in the form: 2011-04-29 Times in form: 23:00:00 All I want the function to return is a number other than 0 if any of the dates/times in Google feed overlap the requested date/time entered in the booking. So I add a function and get the feed from Google: Code: [Select] function checkOverlapG($calendarID, $startdate, $starttime, $enddate, $endtime){ // Create an instance of the Calendar service using an unauthenticated //HTTP client $service = new Zend_Gdata_Calendar(); //Retrieving events in order of start time $query = $service->newEventQuery(); $query->setUser('calendarID'); // Set to $query->setVisibility('private-magicCookieValue') if using MagicCookie auth $query->setVisibility('public'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortOrder('ascending'); //start with first event in future //seFutureevents must be commented out when using start and end times. $query->setFutureevents('true'); $query->setSingleEvents('true'); $query->setMaxResults('200'); //Guess this could be anything, but can possibly make things slower. Default 25 events //$query->setStartMin('2006-12-01'); //$query->setStartMax('2006-12-16); // setStartMax is exclusive, will not include last date. Must add +1 day. // Retrieve the event list from the calendar server try { $eventFeed = $service->getCalendarEventFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); return null; } Now I want to compare the dates and times and see if any of them collide or overlap. I want to add a counter, and if any of the events overlap, I want the counter to add one number. 1. the first thing I do is check if the event feed include. any events. 2. then I add a counter 3. then I run a foreach to retrieve events one at a time 4. then I change the date and time format from Google Event to match the date and time format form the booking. 5. If fullday event from google, no time information is added, so I add this 6. COMPARE DATES AND TIMES and if overlapping events --> n++; I've not gotten this code to work. Probably I'm doing something wrong, and I'm sorry but I'm completely new to this. Getting the Google Calendar data is working fine, and so is changing the format of the dates/times to be same format as request data. After that (and before, I don't know). Code: [Select] $gCount = count($eventFeed); $n = 0; if (gCount>0){ foreach($eventFeed as $event){ foreach ($event->when as $when) { //Getting rid of extra 00's and time zone info for now $startGevent = $when->startTime; $startGevent = str_replace('.000+02:00',"",$startGevent); $endGevent = $when->endTime; $endGevent = str_replace('.000+02:00',"",$endGevent); //Splitting date and time into two variables list($startDateEvent, $startTimeEvent) = split('T',$startGevent); list($endDateEvent, $endTimeEvent) = split('T',$endGevent); //Fill in the blanks if($startTimeEvent!=0) {} else{$startTimeEvent = "00:00:00";} if($endTimeEvent!=0) {} else{$endTimeEvent = "00:00:00";} //Compare dates if($startdate == $endDateEvent){ if($starttime > $endTimeEvent OR $endtime < $startTimeEvent){} else { n++; } } if($enddate == $startDateEvent){ if($endtime < $startTimeEvent OR $starttime > $endTimeEvent){} else { n++; } } } } return $n; } Hello I have created a calendar with a working loop however I need help being able to 1) Add months Jan, Feb etc ( can do this) 1a) being able to click those months as links and select the day I am a little confused with the difference between Symfony Events and Event Listners and Doctrine Events. The Doctrine events look pretty straight forward and are primary used for entity persistence, and I have outlined my understanding below: Doctrine Lifecycle Callbacks. Single entity and single Doctrine event. Method in class. Good performance. Don't have access to Symfony services (all others do) Doctrine Lifecycle Listeners. All entities and single Doctrine event. Separate class and configured in config.service.yaml. Doctrine Entity Listeners. Single entities and single Doctrine event. Separate class and configured in config.service.yaml. Doctrine Lifecycle Subscribers. All entities and multiple Doctrine event. Must implement EventSubscriber (or probably EventSubscriberInterface) Separate class and configured in config.service.yaml.I am more confused with the Symfony events and my interpretation as listed below is likely incorrect. Symfony Event Listeners. Single Symfony event. Separate class and configured in config.service.yaml. More flexible because bundles can enable or disable each of them conditionally depending on some configuration value. Symfony Event Subscribers. All specified Symfony events. Must implement EventSubscriberInterface Separate class but NOT configured in config.service.yaml but in class. Easier to reuse because the knowledge of the events is kept in the class rather than in the service definition.Are they used for totally different purposes or can one use Symfony events to also deal with entities? Where would one want to use these Symfony events? Is there a reason why Doctrine Lifecycle Subscribers are located in src/EventListener and not src/EventSubscriber Are Doctrine Lifecycle and Entity Listeners really only for a single event as I interpret the documentation states, or is it one method per Doctrine event such as the following? App\EventListener\SearchIndexer: tags: - name: 'doctrine.event_listener' event: 'postPersist' - name: 'doctrine.event_listener' event: 'postUpdate'
Hi, I want to restrict my registered user to see video only once per day... Can anyone guide me how can i do this with php??? Thanks Hello everybody , This is my first topic here and I hope I will find the solution for my problem. I want to restrict access to file (for exemple: http://www.mysite.com/files/file0000.zip) to a just a specific IP that will be read from the database. And also store all other IPs trying to access this file. Can this be done, maybe through some php and htaccess? Thank you for any help or any other ideas. hi once again, i got a form that uploads an image, checks formats and all that.. i need to add the filesize restriction. something like this: define ("max_size","20"); //<- 20kb size $size=filesize($_FILES['image']['tmp_name']) if ($size > max_size*1024){ echo "too big filesize"; } else { //...... } how do i put that code, into this code? : <?php $allowedfiletypes = array("jpeg","jpg","gif","png"); $uploadfolder = "uploads/" ; $thumbnailheight = 100; //in pixels $thumbnailfolder = $uploadfolder."thumbs/" ; $action = $_POST['action']; if ($action == "upload") { //echo "<p>Uploading image... " ; if(empty($_FILES['uploadimage']['name'])){ echo '<script type="text/javascript"> {alert("Pasirinkite faila");} </script>'; } else { $uploadfilename = $_FILES['uploadimage']['name']; $fileext = strtolower(substr($uploadfilename,strrpos($uploadfilename,".")+1)); if (!in_array($fileext,$allowedfiletypes)) { echo '<script type="text/javascript"> {alert("Blogas failo tipas");} </script>'; } else { $fulluploadfilename = $uploadfolder.$uploadfilename ; if (move_uploaded_file($_FILES['uploadimage']['tmp_name'], $fulluploadfilename)) { echo '<script type="text/javascript"> {alert("Failas irasytas");} </script>'; $im = imagecreatefromjpeg($fulluploadfilename); if (!$im) { echo '<script type="text/javascript"> {alert("Nepavyko sugeneruoti thumbnail");} </script>'; } else { $imw = imagesx($im); // uploaded image width $imh = imagesy($im); // uploaded image height $nh = $thumbnailheight; // thumbnail height $nw = round(($nh / $imh) * $imw); //thumnail width $newim = imagecreatetruecolor ($nw, $nh); imagecopyresampled ($newim,$im, 0, 0, 0, 0, $nw, $nh, $imw, $imh) ; $thumbfilename = $thumbnailfolder.$uploadfilename ; imagejpeg($newim, $thumbfilename) or die('<script type="text/javascript"> {alert("Nepavyko issaugoti thumbnail");} </script>'); } } else { echo '<script type="text/javascript"> {alert("Nepavyko issaugoti failo");} </script>'; } } } function watermark($original_image,$original_watermark,$destination="") { $image=imagecreatefromjpeg($original_image); list($imagewidth,$imageheight)=getimagesize($original_image); $watermark = imagecreatefrompng($original_watermark); list($watermarkwidth,$watermarkheight)=getimagesize($original_watermark); if($watermarkwidth>$imagewidth || $watermarkheight>$imageheight) { $water_resize_factor = $imagewidth / $watermarkwidth; $new_watermarkwidth = $watermarkwidth * $water_resize_factor; $new_watermarkheight = $watermarkheight * $water_resize_factor; $new_watermark = imagecreatetruecolor($new_watermarkwidth , $new_watermarkheight); imagealphablending($new_watermark , false); imagecopyresampled($new_watermark , $watermark, 0, 0, 0, 0, $new_watermarkwidth, $new_watermarkheight, $watermarkwidth, $watermarkheight); $watermarkwidth = $new_watermarkwidth; $watermarkheight = $new_watermarkheight; $watermark = $new_watermark; } $startwidth = ($imagewidth - $watermarkwidth) / 2; $startheight = ($imageheight - $watermarkheight) / 2; imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); if(!empty($destination)) imagejpeg($image,$destination); else imagejpeg($image); } $original_directory = "uploads/thumbs/"; $watermarked_images = "uploads/thumbs/watermarkedthumbs/"; if ($handle = opendir($original_directory)) { while (false !== ($file = readdir($handle))) { /* exif_imagetype checks if our file is a .jpg file. See manual for more info */ if(!is_file($original_directory.$file)) continue; if(exif_imagetype($original_directory.$file)==2) { watermark($original_directory.$file,"watermark.png",$watermarked_images.$file); } } closedir($handle); } } ?> <form name="newad" method="post" enctype="multipart/form-data" action=""> <label for="file" id="label">Pasirinkti failą: </label> <input type="hidden" name="action" value="upload" /> <input type="file" name="uploadimage" id="file"> <input name="Submit" type="submit" value="įkelti" id="submit"> </form> i tried smth like this, but it shows some error ("Warning: filesize() [function.filesize]: stat failed for 1.jpg in") <?php /* $allowedfiletypes = array("jpeg","jpg","gif","png"); $uploadfolder = "uploads/" ; $thumbnailheight = 100; //in pixels $thumbnailfolder = $uploadfolder."thumbs/" ; */ define ("max_size","20"); $size=filesize($_FILES['uploadimage']['name']); /* $action = $_POST['action']; if ($action == "upload") { //echo "<p>Uploading image... " ; if(empty($_FILES['uploadimage']['name'])){ echo '<script type="text/javascript"> {alert("Pasirinkite faila");} </script>'; } else { $uploadfilename = $_FILES['uploadimage']['name']; $fileext = strtolower(substr($uploadfilename,strrpos($uploadfilename,".")+1)); if (!in_array($fileext,$allowedfiletypes)) { echo '<script type="text/javascript"> {alert("Blogas failo tipas");} </script>'; } else { $fulluploadfilename = $uploadfolder.$uploadfilename ; */ if ($size > max_size*1024){ echo '<script type="text/javascript"> {alert("Per didelis failas");} </script>'; } else { /* if (move_uploaded_file($_FILES['uploadimage']['tmp_name'], $fulluploadfilename)) { echo '<script type="text/javascript"> {alert("Failas irasytas");} </script>'; $im = imagecreatefromjpeg($fulluploadfilename); if (!$im) { echo '<script type="text/javascript"> {alert("Nepavyko sugeneruoti thumbnail");} </script>'; } else { $imw = imagesx($im); // uploaded image width $imh = imagesy($im); // uploaded image height $nh = $thumbnailheight; // thumbnail height $nw = round(($nh / $imh) * $imw); //thumnail width $newim = imagecreatetruecolor ($nw, $nh); imagecopyresampled ($newim,$im, 0, 0, 0, 0, $nw, $nh, $imw, $imh) ; $thumbfilename = $thumbnailfolder.$uploadfilename ; imagejpeg($newim, $thumbfilename) or die('<script type="text/javascript"> {alert("Nepavyko issaugoti thumbnail");} </script>'); } } else { echo '<script type="text/javascript"> {alert("Nepavyko issaugoti failo");} </script>'; } } } } function watermark($original_image,$original_watermark,$destination="") { $image=imagecreatefromjpeg($original_image); list($imagewidth,$imageheight)=getimagesize($original_image); $watermark = imagecreatefrompng($original_watermark); list($watermarkwidth,$watermarkheight)=getimagesize($original_watermark); if($watermarkwidth>$imagewidth || $watermarkheight>$imageheight) { $water_resize_factor = $imagewidth / $watermarkwidth; $new_watermarkwidth = $watermarkwidth * $water_resize_factor; $new_watermarkheight = $watermarkheight * $water_resize_factor; $new_watermark = imagecreatetruecolor($new_watermarkwidth , $new_watermarkheight); imagealphablending($new_watermark , false); imagecopyresampled($new_watermark , $watermark, 0, 0, 0, 0, $new_watermarkwidth, $new_watermarkheight, $watermarkwidth, $watermarkheight); $watermarkwidth = $new_watermarkwidth; $watermarkheight = $new_watermarkheight; $watermark = $new_watermark; } $startwidth = ($imagewidth - $watermarkwidth) / 2; $startheight = ($imageheight - $watermarkheight) / 2; imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); if(!empty($destination)) imagejpeg($image,$destination); else imagejpeg($image); } $original_directory = "uploads/thumbs/"; $watermarked_images = "uploads/thumbs/watermarkedthumbs/"; if ($handle = opendir($original_directory)) { while (false !== ($file = readdir($handle))) { /* exif_imagetype checks if our file is a .jpg file. See manual for more info */ /* if(!is_file($original_directory.$file)) continue; if(exif_imagetype($original_directory.$file)==2) { watermark($original_directory.$file,"watermark.png",$watermarked_images.$file); } } closedir($handle); } } */ ?> any ideas? thanks How do I make it so if I get the question right, I have access to view the next page? For example, if I get this question right in index-1.php correct, it would take me to index-2.php (like in the script below), but if you don't get the question correct in index-1.php, you cannot have access/view index-2.php. Why I need this? Well, if you change the URL http://--------/index-1.php to http://--------/index-2.php, you can easily go from index-1.php to index-2.php without having to answer the question correctly. index-1.php: <?php if(isset($_POST['submit'])){ $number = $_POST['number']; if ($number == "elephant"){ header("Location: http://localhost/index-2.php"); exit();} } ?> <html> <head> <title>PHP Test</title> </head> <b>LEVEL 1</b> <body> <p> <font face="Courier New">c291cmNl</font> </p> <br/></body> </html> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> Answer: <!-- "elephant" --> <input type="text" name="number" /><br /> </select> <input name="submit" type="submit"> </form> Thanks I have a sign up form to send the activation code to the new user via email.My question is how to restrict the user who is not a member using activation form page in PHP unless their use a sign up form first?
here is my sign up form and activation form:
sign up form
<style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12; } .style5 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; } .style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } --> </style> <form name="form1" method="post" action="email-activation-script.php"> <div align="center"> <p class="style5"> Form Registration </p> <table width="35%" border="0"> <tr> <td class="style7">Username</td> <td class="style7">:</td> <td class="style1"><span class="style7"> <label> <input name="username" type="text" id="username"> </label> </span></td> </tr> <tr> <td class="style7"> Email </td> <td class="style7">:</td> <td class="style1"><span class="style7"> <label> <input name="email" type="text" id="email"> </label> </span></td> </tr> <tr> <td class="style7">Password</td> <td class="style7">:</td> <td class="style1"><span class="style7"> <label> <input name="password" type="password" id="password"> </label> </span></td> </tr> <tr> <td class="style7"> </td> <td class="style7"> </td> <td class="style1"><span class="style7"> <label> <input type="submit" name="Submit" value="Register"> <input type="reset" name="Submit2" value="Cancel"> </label> </span></td> </tr> </table> </div> </form> activation form: <form name="form1" method="post" action="check-activation-script.php"> <div align="center"> <table width="35%" border="0"> <tr> <td>Username</td> <td>:</td> <td><label> <input name="username" type="text" id="username"> </label></td> </tr> <tr> <td>Activation Code </td> <td><label>:</label></td> <td><input name="activation_code" type="text" id="activation_code"></td> </tr> <tr> <td> </td> <td> </td> <td><label> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Cancel"> </label></td> </tr> </table> </div> </form> Hi all My code give this: <b>Warning</b>: file_exists(): open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/home/clients/........ I get the tmp folder and check for its existanse and whether it is writeable
$t=sys_get_temp_dir(); Both gives no which is fine, I can process that. I do it to avoid the output above, but I still get that. How should I check for allowed paths? This runs on several systems where I cannot access php.ini or other system stuff.
Ok I am designing a php upload that will take a image file from a form and change the name of the file to the productnumber also recieved from the form. I had it working the otherday now it says Warning: copy() [function.copy]: open_basedir restriction in effect File() is not within the allowed path(s): (/home:/tmp:/usr) addpro.php on line 51. my files are attached.... note that $pnum is the product number gotten from my form and image is the image being uploaded gotten from the form also. The thing is it worked the other day but now it don't is it a change to the server ( I dont run the server) or did I mess up my code since then? I really need a code that will do this two time over once for a small image being put into a folder called small and once for a folder called large both images being uploaded and being changed to $pnum.ext so they will both be displayed when being called out by the product number. but I can work on that after I get this one working. line 51 is $copied = copy($_FILES['image']['tmp_name'], $newname); |