<?php # $Id: template.php,v 1.9 2004/03/31 07:49:07 pcool Exp $

/*
============================================================================== 
	Dokeos - elearning and course management software
	
	Copyright (c) 2004 Dokeos S.A.
	Copyright (c) 2003 University of Ghent (UGent)
	Copyright (c) 2001 Universite catholique de Louvain (UCL)

	Copyright (c) Jean "Example" Programmer (jean@somewhere.net)
	
	For a full list of contributors, see "credits.txt".
	The full license can be read in "license.txt".
	
	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.
	
	See the GNU General Public License for more details.
	
	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
============================================================================== 
*/


/*
============================================================================== 
	   DOKEOS INIT 
============================================================================== 
*/ 

// setting the language file
$langFile="poll";


// global settings initialisation 
// also provides access to main api (inc/lib/main_api.lib.php)
// setting the global file that gets the general configuration, the databases, the languages, ...
include('../../inc/claro_init_global.inc.php');

	
/*
-----------------------------------------------------------
	Header
-----------------------------------------------------------
*/ 

$htmlHeadXtra[]="<script language=\"javascript\" src=\"calendar/popcalendar.js\"></script>";

$htmlHeadXtra[]="<script type=\"text/javascript\" language=\"JavaScript\">

function validnr() 
{
	var f = document.formanswer;
	var number = f.nr.value;

   if (number<2) 
   {
    	alert(\"$langAnswerQuestion\");
    	return false;
   } 
}

function validnew() 
{
	var f = document.newpoll;
	var q = f.question.value;
	
	if (!q) 
	{
    	alert('$langCheckAnswer');
    	return false;
   } 
}

</script>";  


// setting the name of the tool
$nameTools=$langNew;

// breadcrumbs
$interbredcrump[]= array ("url"=>"poll.php", "name"=>"Polls");

/*
-----------------------------------------------------------
			Including some necessary files
-----------------------------------------------------------
*/ 
@include('../../inc/textLib.inc.php');
Display::display_header($nameTools,'Poll');


//stats
include('../../inc/lib/events.lib.inc.php');
event_access_tool(TOOL_POLL);
include('../../inc/lib/text.lib.php');


/*
============================================================================== 
		Variable definitions
============================================================================== 
*/ 
//$is_allowedToEdit = $is_courseAdmin;
$name = $_uid;

// setting the database variables
$poll_cnf["questionTbl"] = $_course["dbNameGlu"]."poll_questions"; 
$poll_cnf["answerTbl"] = $_course["dbNameGlu"]."poll_answers";
$poll_cnf["numberTbl"] = $_course["dbNameGlu"]."poll_number";

/*
-----------------------------------------------------------
			Access Rights
-----------------------------------------------------------
*/ 
// permission stuff
$is_allowedToEdit 	= api_is_allowed_to_edit();
// notice for unauthorized people. 
if ( !api_is_allowed_to_edit) die ("<center>Not allowed</center>");



/*
============================================================================== 
		MAIN CODE
============================================================================== 
*/ 
echo "<br><br>";
api_display_tool_title($langNewPoll);	
 
if ($is_allowedToEdit) 
{

  /* number of questions */
	if (!isset($_POST["start"])) 
	{
		echo "<form method=\"post\" action=\"".$SERVER[PHP_SELF]."\" name=\"formanswer\" onSubmit=\"return validnr()\">",
   			 "<table><tr>",
	   		 "<td colspan=\"2\">$langAnswer</td>",
	   		 "<td><input type=\"text\" size=\"1\" name=\"nr\" value=\"2\"></td>",
    		 "</tr><tr>",
	   		 "<td width=\"30\" valign=\"top\"><input type=\"submit\" value=\"$langGo\" name=\"start\"></form></td>",
	   		 "<form method=\"post\" action=\"poll.php\"><td valign=\"top\"><input type=\"submit\" value=\"$langCancel\" name=\"stop\"></td>",
	   		 "<td>&nbsp;</td>",
	   		 "</tr></table>";		
	}
	/* insert question and answers */
	if ($_POST["start"]==$langGo) 
	{

		echo "<form method=\"post\" action=\"poll.php\" name=\"newpoll\" onSubmit=\"return validnew()\">",
  			 "<table><tr>",
	   		 "<td>$langNewQuestion</td>",
	   		 "<td><input type=\"text\" name=\"question\" size=\"70\"></td>",
	   		 "</tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr>";
		
		for ($i=1;$i<=$nr;$i++)
		{
			echo "<tr>",
  				 "<td>$langNewAnswer $i: </td><td><input type=\"text\" name=\"answers[$i]\" size=\"70\"></td>",
  				 "</tr>";	      	  
		}
			
		echo "<tr><td>&nbsp;</td></tr>";
		
		echo "<tr>",
  			 "<td>$langNewStart</td>",
  			 "<td><table width=\"100%\"><tr>",
  			 "<td width=\"50%\"><input type=\"text\" name=\"startdate\" size=\"12\" value=\"".date("d-m-Y")."\">",
		    " <img src=\"calendar/date.gif\" alt=\"".get_lang('DateRollover')."\" width=\"19\" height=\"17\" border=\"0\" onclick=\"popUpCalendar(this, newpoll.startdate, 'dd-mm-yyyy')\"  align=\"absmiddle\"></td>",
  			 "<td>&nbsp;</td>",
	   	 "<td width=\"50%\"><input type=\"text\" name=\"houra\" size=\"2\" maxlength=\"2\" value=\"".date("H",mktime())."\">:",
		  	 "<input type=\"text\" name=\"mina\" size=\"2\" maxlength=\"2\" value=\"".date("i",mktime())."\">:",
			 "<input type=\"text\" name=\"seca\" size=\"2\" maxlength=\"2\" value=\"".date("s",mktime())."\"> $langNewTime</td>",
		  	 "</tr></table></td>",
		  	 "</tr>";
			 
		echo "<tr>",
  			 "<td>$langNewEnd</td>",
  			 "<td><table width=\"100%\"><tr>",
  			 "<td width=\"50%\"><input type=\"text\" name=\"enddate\" size=\"12\" value=\"".date("d-m-Y")."\">",
  		    " <img src=\"calendar/date.gif\" alt=\"".get_lang('DateRollover')."\" width=\"19\" height=\"17\" border=\"0\" onclick=\"popUpCalendar(this, newpoll.enddate, 'dd-mm-yyyy')\"  align=\"absmiddle\"></td>",
  			 "<td>&nbsp;</td>",
  			 "<td width=\"50%\"><input type=\"text\" name=\"hourb\" size=\"2\" maxlength=\"2\" value=\"".date("H",mktime())."\">:",
  			 "<input type=\"text\" name=\"minb\" size=\"2\" maxlength=\"2\" value=\"".date("i",mktime())."\">:",
  			 "<input type=\"text\" name=\"secb\" size=\"2\" maxlength=\"2\" value=\"".date("s",mktime())."\"> $langNewTime</td>",
  			 "</tr></table></td>",
  			 "</tr>";
		
		echo "</tr><tr><td>&nbsp;</td></tr>";
      echo "<tr>",
          "<td>$langAnonymous1</td>",
          "<td><input type=\"radio\" name=\"save\" value=\"1\" checked>NAI ",
          " <input type=\"radio\" name=\"save\" value=\"0\">OXI </td> ",
          "</tr>";
      	
		echo "</tr><tr><td>&nbsp;</td></tr><tr><td>&nbsp;</td></tr><br>",
  			 "<tr>",
  			 "<td valign=\"top\"><input type=\"hidden\" name=\"nr\" value=\"$nr\">",
  			 "<input type=\"submit\" value=\"$langGo1\" name=\"start\" >",
          "</form></td>",
  			 "<form method=\"post\" action=\"poll.php\"><td valign=\"top\"><input type=\"submit\" value=\"$langCancel\" name=\"stop\"></td>",
  			 "</tr></table>";
	}
			


}


/*
============================================================================== 
		DOKEOS FOOTER 
============================================================================== 
*/ 

@include('../../inc/claro_init_footer.inc.php');
?>
