Jump to content

clausowitz

Members
  • Posts

    79
  • Joined

  • Last visited

    Never

Posts posted by clausowitz

  1. I show addresses on a webpage and want to show the locations on a small map.

    I have a javascript function for the maps using Google Api 3. The function is working but I have no idea to show it in my php-loop. Maybe it's not possible due to the difference in javascript and php.

            while($row = mysql_fetch_array($sql)) {
    
            $id = $row["id"];
            $name = $row["name"];
            $spec = $row["specialism"];
            $address = $row["address"];
            $telephone = $row["telephone"];
            $lat = $row["lat"];
            $lon = $row["lng"];
            $loc = "$lat $lon";
            if(($lat > '0') && ($lat > '0')) {
    
    }
    
    $outputList .= '<table cellspacing="0" bgcolor="#FFFFFF" border="0"><tr>
    <td colspan="2" class="boardHeader" style="padding-left: 6px;">' . $name . '</td>
    <td class="boardHeader" style="color:#3300CC; padding-left:6px; padding-right:2px; font-weight:bold" align="right">' . $spec . '</td>
    </tr>
       <td> </td>
       <td valign="left">  </td>
       <td rowspan="4"><div id="map_canvas-<?php echo $num2++; ?>" style="width:200px; height:150px">';
       echo "javascript:GetMedicalMap($lat,$lon);";
    
    $outputList .= '</div></td>
    </tr>
    <tr>
       <td style="padding-left: 6px;">Address:</td>
       <td colspan="1" style="vertical-align:middle" width="42%" >' . $address . ' </td>
    </tr>
    <tr>
       <td style="padding-left: 6px;">Telephone:</td>
       <td >' . $telephone . '</td>
    </tr>
    <tr>
        <td >  </td>
        <td >  </td>
    </tr><br />
    ';
            }

     

    thanks for any advise,

    Marco

  2. OK, you mean all this has to go with AJAX?

     

    $short=$_POST['short'];

      $location=$_POST['location'];

      if(isset($_POST['type'])) {

      $type=$_POST['type']; }

      $starthour=$_POST['starthour'];

      $startmin=$_POST['startmin'];

      $endhour=$_POST['endhour'];

      $endmin=$_POST['endmin'];

      $reminders=$_POST['reminders'];

          $reminders=addslashes($reminders);

      if(isset($_POST['view'])) {

      $view=$_POST['view']; }

      if(isset($_POST['val'])) {

    $val=$_POST['val']; }

  3. I got it to work but not quiet. WHen I use following function:

     

    $(function() {

        $("form#form33").submit(function() {

            $("#dvloader").show();

            $.post("editcalendar.php", function(data) {

      alert("Your event has been created, Close this window.");

    });

      return false;

    });

     

    I see the loading gif but the data doesn't get saved to the table.

     

    When I take out the "return false" to go back to the html

    The data gets saved but I don't see the loading gif.

     

    Also the loading gif gets displayed in the upper left corner of the form, even with this:

     

    #dvloader{

    position:absolute;

    top:300;

    right:300;

    z-index:1;

    }

     

    What am I missing here (except knowledge of course)

  4. Sorry for being such an amateur.

    What I basically do is load a page called editcalendar.php. The users fills in an event with date and all and hits Submit.

    The event is saved in the database and all users get an email. During this process I want the loading.gif displayed to make

    sure people don't click Submit again thinking nothings happening.

    When the process is done the loading.gif should dissapear and a text should show up saying: Your event has been created, Close this window.

     

    So if I use the $.post function I would use it like this:

     

    $.post("editcalendart.php", function(data) {

      alert("Your event has been created, Close this window.");

    });

     

     

  5. How would that work?

    you mean like this:

    <form id='form33' action='editcalendar.php?ID=$ID' method='post'>

     

    <script language="javascript" type="text/javascript">

    function toggleDiv(divid){

       

        if(document.getElementById(divid).style.display == 'none'){

          document.getElementById(divid).style.display = 'block';

        }else{

          document.getElementById(divid).style.display = 'none';

        }

      }

    </script>

  6. I worked a bit with the code you gave me so the email doesn't take that long.

    Still I would like to show a loading gif. I tried with AJAX but it doesn't show:

     

    <div style="display:none" id="dvloader"><img src="images/loading.gif" /></div>

     

    $(function() {

        $(".changepass").click(function() {

            $("#dvloader").show();

            $(".block1").load("editcalendar.php", function(){ $("#dvloader").hide(); });

            return false;

        });

    });

     

    don't know exactly where to put it.

  7. I tried the following, but still it doesn't show. I don't get it.

    <?PHP
      $show .= '<input type="submit" name="submit" id="submit" onclick="$("#loading").show();" value="submit"></form>';
      $show .= '<div id="loading" align="center" style="display:none;"><img src="images/loading2.gif" alt="" />Loading!</div>';
    ?>
    

  8. Hi All,

     

    not sure if this is a php Q but maybe someone has experience with this.

    I use a form for people to add an item to the bulletin board. Sometimes the loading of the page takes very long and people think it didn't work so they click reload and post the item twice. I thought of adding a loading.gif so people know they have to wait. Anyone know how and where to put that in?

    <?PHP
       if(isset($_POST['submit']))
       {
    
      if ($_POST['type']<>"") {  
    
      $poster_id = $_SESSION['id'];
      $ID=$_GET['ID'];
      $short=$_POST['short'];
      $location=$_POST['location'];
    	  if(isset($_POST['type'])) {
    		  $type=$_POST['type']; }
      $starthour=$_POST['starthour'];
      $startmin=$_POST['startmin'];
      $endhour=$_POST['endhour'];
      $endmin=$_POST['endmin'];
      $reminders=$_POST['reminders'];
          $reminders=addslashes($reminders);
      if(isset($_POST['view'])) {
      	$view=$_POST['view']; }
      if(isset($_POST['val'])) {
    	$val=$_POST['val']; }
      
      $sql = mysql_query("SELECT * from bl_calender where dateclass='$ID' AND viewable='1'");
      $numrows = mysql_num_rows($sql);
    		// if the event exists then we want to edit it
    	if ($numrows > 0){
    		// only the owner can edit an event
    		while($row = mysql_fetch_array($sql)){
    			if($row['poster_id'] == $logOptions_id || $account_type == 'c' ){
    
    		      $editcal="update bl_calender set datecotent='$reminders', location='$location', type='$type', starthour='$starthour', startmin='$startmin', endhour='$endhour', endmin='$endmin', short='$short', viewable='$view' where dateclass='$ID'";
    		      mysql_query($editcal) or die("Could not edit calendar");
    	          $msgToUser = '<br /><br /><font color="#FF0000">Your event has been updated. Close this window.</font><p></p>';
    			    include_once 'msgToUser2.php';
    			} else {  // you are not the owner
    				$msgToUser = '<br /><br /><font color="#FF0000">Sorry but only the owner can change the event details.<br> Close this window.</font><p></p>';
    			    include_once 'msgToUser2.php';
    				   }
    
    			         }
    
    }  else {      // it's a new event we want to add
    
             $createevent="Insert into bl_calender (poster_id, dateclass, starthour, startmin, endhour, endmin, location, type, short, datecotent, viewable ) values ('$poster_id', '$ID', '$starthour', '$startmin',  '$endhour', '$endmin', '$location', '$type', '$short', '$reminders', '1')";
             mysql_query($createevent) or die(mysql_error());
    
    $sql2 = mysql_query("SELECT * FROM myMembers WHERE notification_calendar='1'"); // query the members who want an email
    $numrows = mysql_num_rows($sql2);
    if ($numrows > 0){
    	while($row = mysql_fetch_array($sql2)){
    		if($row['email'] =="") {
    			$to = $row['email_work'];
    			} else {
    			$to = $row['email'];
    			}
    			$your_firstname = $row['firstname'];
    			$your_lastname = $row['lastname'];
    
    					// send an email to everyone who wants it
    					$webmaster = "KAI-DEFAT@minbuza.nl";
    					$headers = "From: MAAC Webmaster<$webmaster>";
    					$subject = "A new message has been posted in the MAAC Calendar.";
    					$message = "Hello $your_firstname $your_lastname, a new event has been posted in the MAAC Calendar.\n";
    					$message .= "Goto the MAAC website to get the details.\n";
    					$message .= "Click here to view the Calendar $dyn_www/Web_Intersect/calen.php\n";
    					// send email
    					mail($to, $subject, $message, $headers);
    
    	}
    				 }
    
    }
    
    	$msgToUser = '<br /><br /><font color="#FF0000">Your event has been created, Close this window.</font><p></p>';
    			    include_once 'msgToUser2.php';
    
    }
    
    ?>
    

  9. I have a form where people have to fill in some fields and send an email. When there is an error the user has to go back to the form with:

    if (!isset($_POST['checkbox'])) {  
    $msgToUser = '<br /><br /><font color="#FF0000">You did not add any recipients!<br><a href="javascript: history.go(-1)">Go Back</a></font>';
        include_once 'msgToUser.php'; 
        exit();
    }  

     

    I want to save the data that has been filled in the textarea so he doesn't have to type eveything again.

    I tried several options but the textarea keeps getting blank.

     

    <?php
    $message = isset($_POST['message']) ? $_POST['message'] : '';
    
    $fhtml = "<p>Welcome <b>'$logOptions_username'</b> write your email here.   <a href=\"#\" onclick=\"return false\" onmousedown=\"javascript:toggleViewFlags('country_flags');\">Add Recipients</a>
    <br>
    </p><input type=hidden name=post value=yes><p>
    Subject:<br>
    <input type=text name=name size=100>
    </p>
    <p>
    Message:<br>
    <textarea name=message rows=10 cols=75>$message</textarea>
    </p>
    <p>
    <input type=submit name=submit value=\"Send\">
          $sendMsg
    </p>
    ";
    echo $fhtml;
    ?>

     

    This code is apparently not working.

     

    Marco

  10. Here is all my code:

     

     <?php
    
    $image_name = '';
    $theFileName = '';
    $name=$_POST['name'];
    $message=$_POST['message'];
    $image = $HTTP_POST_FILES['image']['name']; 
    $document = $HTTP_POST_FILES['document']['name'];
    $document = str_replace("#", "No.", $document);
    $document = str_replace("$", "Dollar", $document);
    $document = str_replace("%", "Percent", $document);
    $document = str_replace("^", "", $document);
    $document = str_replace("&", "and", $document);
    $document = str_replace("*", "", $document);
    $document = str_replace("?", "", $document); 
    $document = str_replace(" ", "_", $document);
    $uploaddir = "documents/";
    $path = $uploaddir.$document;
    $logOptions_id = $_SESSION['id'];
    $poidsMax = ini_get('post_max_size');
    // Name and Message required
    if (( $name == "") || ( $message == "")) {
    print "<p align=center>Please go back to complete all fields!<p>";
    echo $name;
    }
    else {
    
    //define a maxim size for the uploaded images in Kb
    define ("MAX_SIZE","1000"); 
    
    //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
    function getExtension($str) {
             $i = strrpos($str,".");
             if (!$i) { return ""; }
             $l = strlen($str) - $i;
             $ext = substr($str,$i+1,$l);
             return $ext;
    }
    
    //This function reads the extension of the file.
    $allowedExtensions = array("doc", "pdf", "xls");
    function isAllowedExtension($fileName) {
      global $allowedExtensions;
    return in_array(end(explode(".", $fileName)), $allowedExtensions);
    }
    
    $errors=0;
    
    if($image<>"") 
    {
    	//reads the name of the file the user submitted for uploading
    	$image=$_FILES['image']['name'];
    	if ($image) 
    	{
    	//get the original name of the file from the clients machine
    		$filename = stripslashes($_FILES['image']['name']);
    	//get the extension of the file in a lower case format
      		$extension = getExtension($filename);
    		$extension = strtolower($extension);
    	//if it is not a known extension, we will suppose it is an error
    //otherwise we will do more tests
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
    		{
    	//print error message
    			$msgToUser = '<br /><br /><font color="#FF0000">You tried to upload a picture with an unknown extension.</font>';
        include_once 'msgToUser.php';
    			$errors=1;
    		}
    		else
    		{
    	//get the size of the image in bytes
    $size=filesize($_FILES['image']['tmp_name']);
    
    //compare the size with the maxim size we defined and print error if bigger
    if ($size > MAX_SIZE*1024)
    {
    $msgToUser = '<br /><br /><font color="#FF0000">You exceeded the filesize limit. Picture did not get posted.</font>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    
    	//we will give an unique name, for example the time in unix time format
    $image_name=time().'.'.$extension;
    	//the new name will be containing the full path where will be stored (images folder)
    $newname="pictures/".$image_name;
    	//we verify if the image has been uploaded, and print error instead
    $copied = copy($_FILES['image']['tmp_name'], $newname);
    if (!$copied) 
    {
    $msgToUser = '<br /><br /><font color="#FF0000">Ooops something went wrong.</font><p><a href="../index.php">Go Back</a></p>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    	}
    }
    }
    
    	//If no errors registred, print the success message
    if(( $image) && !$errors) 
    {
    	$msgToUser = '<br /><br /><font color="#FF0000">Message has been posted successfully.</font><p><a href="../index.php">Go Back</a></p>';
        include_once 'msgToUser.php';
    }	
    
    if($document != ""){ //AS LONG AS A FILE WAS SELECTED...
    
    //compare the size with the maxim size we defined and print error if bigger
    $fsize=filesize($_FILES['document']['tmp_name']);
    if (($fsize/1024) > $poidsMax*1024)
    {
    $msgToUser = '<br /><br /><font color="#FF0000">You exceeded the filesize limit. Document did not get posted.</font>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    
    if(isAllowedExtension($HTTP_POST_FILES['document']['tmp_name'])) {
    if(copy($HTTP_POST_FILES['document']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...
    		//GET FILE NAME
    		$theFileName = $HTTP_POST_FILES['document']['name'];
    		//GET FILE SIZE
    		$theFileSize = $HTTP_POST_FILES['document']['size'];
    		if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
    			$theDiv = $theFileSize / 1000000;
    			$theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
    		} else { //OTHERWISE DISPLAY AS KB
    			$theDiv = $theFileSize / 1000;
    			$theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
    		}
    
    } else { 
    $msgToUser = '<br /><br /><font color="#FF0000">Ooops something went wrong.</font><p><a href="../index.php">Go Back</a></p>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    
    } 
    
    }
    
    $name = strip_tags($name, '');
    $message = strip_tags($message, '');
    
    $sql = mysql_query("INSERT INTO bulletin_board (posting_date, member_id, title, subject, picture, document) VALUES(now(),'$logOptions_id', '$name','$message', '$image_name', '$theFileName')") or die (mysql_error());
    
    }
    
    $msgToUser = '<br /><br /><font color="#FF0000">Message has been posted successfully.</font><p><a href="../index.php">Go Back</a></p>';
        include_once 'msgToUser.php';
    ?> 

     

    I know my code is not like a good example of php coding but I am only a beginner.

     

    Regards

    Marco

  11. Hi All,

     

    I have a code to upload a file to the server. Somehow the files don't get uploaded, although the record is add to the database.

    I have no clue why it doesn't work. The settings of the folder where the docs goto is set to 777.

     

    <?php
    $uploaddir = "documents/";
    $path = $uploaddir.$document;
    
    //This function reads the extension of the file.
    $allowedExtensions = array("doc", "pdf", "xls");
    function isAllowedExtension($fileName) {
      global $allowedExtensions;
    return in_array(end(explode(".", $fileName)), $allowedExtensions);
    }
    
    if($document != ""){ //AS LONG AS A FILE WAS SELECTED...
    
    //compare the size with the maxim size we defined and print error if bigger
    $fsize=filesize($_FILES['document']['tmp_name']);
    if (($fsize/1024) > $poidsMax*1024)
    {
    $msgToUser = '<br /><br /><font color="#FF0000">You exceeded the filesize limit. Document did not get posted.</font>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    
    
    if(isAllowedExtension($HTTP_POST_FILES['document']['tmp_name'])) {
    if(copy($HTTP_POST_FILES['document']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...
    		//GET FILE NAME
    		$theFileName = $HTTP_POST_FILES['document']['name'];
    		//GET FILE SIZE
    		$theFileSize = $HTTP_POST_FILES['document']['size'];
    		if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
    			$theDiv = $theFileSize / 1000000;
    			$theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
    		} else { //OTHERWISE DISPLAY AS KB
    			$theDiv = $theFileSize / 1000;
    			$theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
    		}
    
    
    } else { 
    $msgToUser = '<br /><br /><font color="#FF0000">Ooops something went wrong.</font><p><a href="../index.php">Go Back</a></p>';
        include_once 'msgToUser.php';
    $errors=1;
    }
    
    } 
    
    }
    
    $name = strip_tags($name, '');
    $message = strip_tags($message, '');
    
    $sql = mysql_query("INSERT INTO bulletin_board (posting_date, member_id, title, subject, picture, document) VALUES(now(),'$logOptions_id', '$name','$message', '$image_name', '$theFileName')") or die (mysql_error());
    
    

     

    Marco

  12. thanks for this sunfighter. Only the problem that I had was that I have about 20 of those divs.

    I came up with this solution. Let me know what you think.

    <?php 
    if (isset($_COOKIE['contentDivImg9'])) {
    $showhide9 = $_COOKIE['contentDivImg9']; }
    	else { $showhide9 = "block"; }
    	if ( $showhide9 == "block") { $button9 = 'x'; } else { $button9 = 'o';}
    ?>

     

    Just have to find something for the alt text: Show this window or Hide this window.

  13. Hi All,

     

    I use a cookie to save the status of divs on my page. When someone clicks the "hide" button then this code runs:

    function toggle5(showHideDiv, switchImgTag) {
            var ele = document.getElementById(showHideDiv);
            var imageEle = document.getElementById(switchImgTag);
            if(ele.style.display == "block") {
                    ele.style.display = "none";
    			setCookie(showHideDiv,'false',9999);
    			imageEle.innerHTML = '<img src="images/o.gif" title="Show this window" border="0" align="right">';
            }
            else {
                    ele.style.display = "block";
                    setCookie(showHideDiv,'true',9999);
    			imageEle.innerHTML = '<img src="images/x.gif" title="Hide this window" border="0" align="right">';
            }
    }

    Now the window is hidden. I save a cookie with the name of the div and the value "false".

    When the page is reloaded it should check which divs should be hidden and then hide them.

    How can I use javascript for this?

  14. Hi All,

     

    I have some javascript on my page that toggles the visibility of my divs.

    I want to save the status of a div in a cookie for later.

    The code to change the visibility is working but I cannot save it to the cookie and read

    the status of all divs on loading of the page.

    <script language="javascript" type="text/javascript"> 
    name='open';
    function toggle5(showHideDiv, switchImgTag) {
            var ele = document.getElementById(showHideDiv);
            var imageEle = document.getElementById(switchImgTag);
            if(ele.style.display == "block") {
                    ele.style.display = "none";
    			createCookie(name,'false',0);
    			imageEle.innerHTML = '<img src="images/o.gif" title="Show this window" align="right">';
            }
            else {
                    ele.style.display = "block";
                    createCookie(name,'true',0);
    			imageEle.innerHTML = '<img src="images/x.gif" title="Hide this window" align="right">';
            }
    }
    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
    	var c = ca[i];
    	while (c.charAt(0)==' ') c = c.substring(1,c.length);
    	if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    function createCookie(name,value,days) {
    if (days) {
    	var date = new Date();
    	date.setTime(date.getTime()+(days*24*60*60*1000));
    	var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }
    function checkCookie(name) {
        var x = readCookie(name)
        if (x == 'false') {
        	document.getElementById('showHideDiv').style.display = 'none'
        } else if (x == 'true') {
            document.getElementById('showHideDiv').style.display = 'block'
        }
    }
    </script>
    <body onload="javascript:checkCookie('open')">

  15. What about this?

    I can't get it right with the quotes:

    <?php if (isset($_SESSION['idx'])) {      
    echo '<div class="containerheader" id="titleTextImg"><strong>Military Attachés accredited in Egypt</strong>';
    echo '<a id="imageDivLink8" href="javascript:toggle5("contentDivImg8", "imageDivLink8");"><img src="images/x.gif" align="right"></a></div>';
    echo '<div class="container" id="contentDivImg8" style="font-size:15px; display:block; margin-bottom:5px;">
            <a href="member_countries.php"><img src="images/worldmap.gif" width="300" height="184" alt="Member Countries" title="Member Countries" border="0" /></a>
            <br /><span style="font-size:12px;">Click somewhere on the map to open the member countries page.</span></div><br />';}
          ?>  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.