<?php
/***********************************
 pragmaMx  Content Management System
 Copyright (c) 2005 pragmaMx Dev Team - http://pragmaMx.org
 ***********************************
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 ***********************************
	$Source: /cvsroot/pragmamx/stable/blocks/block-Webcams.php,v $
 $Revision: 1.0 $
 $Author: jubilee $
 $Date: 2005/06/30 18:14:21 $
 ***********************************
 this file based on:
 Webcam Module 2.2 for PhP-Nuke 6.5 - 7.3
 By: Dragonz' Webmaster (tig@online.be)
 Copyright © 2003 by Dragonz
 **********************************/
if (!defined("mxMainFileLoaded")) die ("You can't access this file directly...");

$modname = "Webcams";
mxGetLangfile($modname);

global $prefix, $randomcam, $camcheck;
require_once("modules/$modname/config.php");

$content="";

//Webcam Select

$camcount = sql_num_rows(sql_query("SELECT * FROM ".$prefix."_webcams_block"));

if (!$randomcam)
{
	$sql = "SELECT camblock, title, camid from ".$prefix."_webcams_block";
}
else
{
	$camlist = array ();
	$sql6666 = "SELECT lid from ".$prefix."_webcams";
	$result6666 = sql_query($sql6666);
	while ($row6666 = sql_fetch_row($result6666))
	{
		$camid = $row6666[0];
		array_push ($camlist, $camid);
	}
	$maxcount = count($camlist);
	srand ((float) microtime() * 10000000);
	$rand = rand(0,$maxcount-1);
	$randid = $camlist[$rand];
	$sql = "SELECT camurl, title, lid from ".$prefix."_webcams WHERE lid = $randid";
}

$result = sql_query($sql);
while ($row = sql_fetch_row($result))
{
    $camurl = $row[0];
    $title = $row[1];
    $lid = $row[2];
	if ($camurl)
	{
	    if ($camcheck)
        {
        	@ini_set("allow_url_fopen", "On");
            $image_info = @getimagesize("$camurl");
            $type=$image_info[2];
            if ($type == 0)
            {
                $camurl="images/webcams/No_cam.jpg";
                $imagehw = @GetImageSize($camurl);
                $h = ($imagehw[1]+40);
                $w = ($imagehw[0]+20);
            }
            else
            {
                $h = ($image_info[1]+40);
                $w = ($image_info[0]+20);
            }
            @ini_restore("allow_url_fopen");
        }
        else
        {
            $h = 320;
            $w = 380;
        }
		$content .= "<center><a href=\"javascript:OpenCamWindow('$h', '$w', '$lid');\"><img height=\"75\", width=\"100\" src=\"".$camurl."\" border=\"0\" alt=\"\"></a>";
	}
	else
	{
		$content .="<center><b>No Cam Yet</b></center>";
	}
	if ($camcount > 1)
	{
	$content .= "<br /><br />";
	}
	$camcount--;
}
$content .= "<br /><a href=modules.php?name=Webcams>"._MORECAMS."</a>";
unset($rand, $randid, $maxcount, $image_info, $camlist, $h, $w, $sql, $result, $row6666, $result6666, $sql6666, $lid, $i, $typ, $imagehw, $camcount, $title, $camurl);
?>
