template1.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * @package dokeos.survey
  18. * @author
  19. * @version $Id: template1.php 10705 2007-01-12 22:40:01Z pcool $
  20. */
  21. // name of the language file that needs to be included
  22. $language_file='survey';
  23. // including the global dokeos file
  24. require_once ('../inc/global.inc.php');
  25. // including additional libraries
  26. /** @todo check if these are all needed */
  27. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  28. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  29. require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
  30. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  31. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  32. require_once (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  33. require_once (api_get_path(LIBRARY_PATH)."/surveymanager.lib.php");
  34. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  35. // Database table definitions
  36. /** @todo use database constants for the survey tables */
  37. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  38. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  39. $survey_user_info_table = Database :: get_main_table(TABLE_MAIN_SURVEY_USER);
  40. $table_reminder = Database:: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  41. $surveyid = $_REQUEST['surveyid'];
  42. $uid = $_REQUEST['uid'];
  43. $uid1 = $_REQUEST['uid1'];
  44. $db_name = $_REQUEST['db_name'];
  45. $temp = $_REQUEST['temp'];
  46. $mail = $_REQUEST['mail'];
  47. $sql_sname = "SELECT * FROM $db_name.survey where survey_id='$surveyid'";
  48. $res_sname = api_sql_query($sql_sname,__FILE__,__LINE__);
  49. $obj_sname = mysql_fetch_object($res_sname);
  50. $surveyname = $obj_sname->title;
  51. $sql_check="SELECT 1
  52. FROM $survey_user_info_table as survey_user_info
  53. INNER JOIN $db_name.survey as survey
  54. ON survey.survey_id = survey_user_info.survey_id
  55. AND survey.code = '".$obj_sname->code."'
  56. WHERE email = '$mail' AND attempted = 'yes'";
  57. $res_check=api_sql_query($sql_check);
  58. if(mysql_num_rows($res_check)>0)
  59. {
  60. if($lang=='english')
  61. $error_message="You have already attempted this survey!";
  62. else if($lang=='french')
  63. $error_message="Vous avez déjà répondu à cette enquête!";
  64. else if($lang=='dutch')
  65. $error_message="U heeft deze enquête reeds ingevuld, dank u!";
  66. Display::display_error_message($error_message);
  67. exit;
  68. }
  69. if(isset($mail))
  70. {
  71. $sql_update = "UPDATE $table_reminder SET access='1' WHERE db_name='$db_name' AND sid='$surveyid' AND email='$mail'";
  72. api_sql_query($sql_update);
  73. }
  74. if(isset($_POST['Next']))
  75. {
  76. $firstname = $_REQUEST['firstname'];
  77. $lastname = $_REQUEST['lastname'];
  78. $temp = $_REQUEST['temp'];
  79. $surveyid = $_REQUEST['surveyid'];
  80. $uid = $_REQUEST['uid'];
  81. $uid1 = $_REQUEST['uid1'];
  82. $db_name = $_REQUEST['db_name'];
  83. $email = $_REQUEST['email'];
  84. $mail = $_REQUEST['mail'];
  85. $organization = $_REQUEST['organization'];
  86. $age = $_REQUEST['age'];
  87. if($uid!='')
  88. {
  89. $registered='Y';
  90. }
  91. else
  92. {
  93. $registered='N';
  94. }
  95. $sql="SELECT * FROM $survey_user_info_table WHERE email = '$mail'";
  96. $result=api_sql_query($sql);
  97. $obj=mysql_fetch_object($result);
  98. $new_mail=$obj->email;
  99. $user_id=$obj->user_id;
  100. if($new_mail!='')
  101. {
  102. $uid1=$user_id;
  103. $sql_ins = "update $survey_user_info_table set user_id='$uid1', survey_id='$surveyid', db_name='$db_name', firstname='$firstname', lastname='$lastname', organization='$organization', age='$age' where user_id='$uid1'";
  104. $result=api_sql_query($sql_ins);
  105. header("location:welcome_1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
  106. exit;
  107. }
  108. else
  109. {
  110. $sql="SELECT max(user_id) FROM $survey_user_info_table";
  111. $result=api_sql_query($sql);
  112. $user_id=mysql_result($result, 0, max('user_id'));
  113. $uid1=$user_id+1;
  114. $sql_ins="INSERT INTO $survey_user_info_table(id,user_id,survey_id,db_name,firstname,lastname,email,organization,age, registered, attempted) values('','$uid1','$surveyid', '$db_name','$firstname','$lastname','$_REQUEST[mail]','$organization','$age','$registered', 'no')";
  115. $result_ins=api_sql_query($sql_ins);
  116. header("location:welcome_1.php?temp=$temp&surveyid=$surveyid&uid1=$uid1&db_name=$db_name&mail=$mail&lang=$lang");
  117. exit;
  118. }
  119. }
  120. if($uid=='')
  121. {
  122. $sql_u="SELECT * FROM $survey_user_info_table WHERE user_id='$uid1' or email='$mail'";
  123. }
  124. else{
  125. $sql_u="SELECT * FROM $table_user WHERE user_id='$uid'";
  126. }
  127. $res = api_sql_query($sql_u,__FILE__,__LINE__);
  128. $obj=@mysql_fetch_object($res);
  129. $email=$obj->email;
  130. $user_idd=$obj->user_id;
  131. $rs=mysql_query("SELECT * FROM $table_survey_question");
  132. $row=mysql_num_rows($rs);
  133. $page=ceil($row/4);
  134. if(isset($_GET[num]))
  135. {
  136. $num=$_GET[num];
  137. if($num>$page)
  138. {
  139. header("Location:test.php");
  140. exit;
  141. }
  142. }
  143. else
  144. {
  145. $num = 1;
  146. }
  147. $lower = $num*4-4;
  148. Display::display_header($tool_name);
  149. api_display_tool_title($surveyname);
  150. api_display_tool_title($tool_name);
  151. if($error_message)
  152. {
  153. Display::display_error_message($error_message);
  154. }
  155. ?>
  156. <link href="../css/survey_white.css" rel="stylesheet" type="text/css">
  157. <table width="727" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F6F5F5">
  158. <tr>
  159. <td width="23" height="21">&nbsp;</td>
  160. <td height="21">&nbsp;</td>
  161. <td width="20" height="21">&nbsp;</td>
  162. </tr>
  163. <tr>
  164. <td>&nbsp;</td>
  165. <td valign="top">
  166. <table width="100%" height="132" border="0" cellpadding="0" cellspacing="0" bgcolor="#F6F5F5">
  167. <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
  168. <!--<form method="post" action="surveytemp_white.php">-->
  169. <input type="hidden" name="uid" value="<?php echo $uid;?>">
  170. <input type="hidden" name="surveyid" value="<?php echo $surveyid;?>">
  171. <input type="hidden" name="db_name" value="<?php echo $db_name;?>">
  172. <input type="hidden" name="temp" value="<?php echo $temp;?>">
  173. <input type="hidden" name="email" value="<?php echo $email;?>">
  174. <input type="hidden" name="mail" value="<?php echo $mail;?>">
  175. <input type="hidden" name="lang" value="<?php echo $lang;?>">
  176. <input type="hidden" name="uid1" value="<?php echo $uid1;?>">
  177. <tr>
  178. <td width="32%" class="text"><?if($lang=='french')echo 'Prénom :'; else if($lang=='dutch')echo 'Voornaam :'; else echo 'First Name :' ;?></td>
  179. <td width="68%"><input type="text" name="firstname" maxlength="40" value="<?php echo mysql_result($res,0,"firstname");?>"></td>
  180. </tr>
  181. <tr>
  182. <td class="text"><?if($lang=='french')echo 'Nom :'; else if($lang=='dutch')echo 'Naam :'; else echo ' Last Name :' ;?></td>
  183. <td><input name="lastname" type="text" id="lastname" maxlength="40" value="<?php echo mysql_result($res,0,"lastname");?>"></td>
  184. </tr>
  185. <tr>
  186. <td class="text"><?if($lang=='french')echo 'Email :'; else if($lang=='dutch')echo 'Email :'; else echo 'EMail :' ;?></td>
  187. <td class="text"><?php echo $mail;?></td>
  188. </tr>
  189. <tr>
  190. <td class="text"><?if($lang=='french')echo 'Organisation :'; else if($lang=='dutch')echo 'Organisatie :'; else echo 'Organization :' ;?></td>
  191. <td><!--<input name="organization" type="text" id="organization" maxlength="40" value="<?if($uid1){echo mysql_result($res,0,"organization");} else{echo "";}?>">-->
  192. <?
  193. if($lang=='dutch')
  194. {
  195. $fp=fopen("dutch_names.txt","r");
  196. $names=file('dutch_names.txt');
  197. }
  198. else if($lang=='french')
  199. {
  200. $fp=fopen("french_names.txt","r");
  201. $names=file('french_names.txt');
  202. }
  203. else if($lang=='english')
  204. {
  205. $fp=fopen("all_names.txt","r");
  206. $names=file('all_names.txt');
  207. }
  208. $count=count($names);
  209. ?>
  210. <select name='organization'>
  211. <?
  212. if($uid1)
  213. {
  214. echo "<option>";
  215. echo mysql_result($res,0,'organization');
  216. echo "</option>";
  217. for($i=0;$i<$count;$i++)
  218. {
  219. $name=$names[$i];
  220. ?>
  221. <option value='<?php echo $name;?>'>
  222. <?php echo $names[$i];?>
  223. </option>
  224. <?
  225. }
  226. }
  227. elseif($email)
  228. {
  229. echo "<option>";
  230. echo mysql_result($res,0,'organization');
  231. echo "</option>";
  232. for($i=0;$i<$count;$i++)
  233. {
  234. $name=$names[$i];
  235. ?>
  236. <option value='<?php echo $name;?>'>
  237. <?php echo $names[$i];?>
  238. </option>
  239. <?
  240. }
  241. }
  242. else
  243. {
  244. for($i=0;$i<$count;$i++)
  245. {
  246. $name=$names[$i];
  247. ?>
  248. <option value='<?php echo $name;?>'>
  249. <?php echo $names[$i];?>
  250. </option><?
  251. }
  252. }
  253. ?>
  254. </select></td>
  255. </tr>
  256. <tr>
  257. <td>&nbsp;</td>
  258. <?php
  259. if($user_idd)
  260. {?>
  261. <td><input type="submit" name="Next" value="<?if($lang=='french')echo 'Suivant'; else if($lang=='dutch')echo 'Volgende'; else echo 'Next' ;?>"></td>
  262. <?php
  263. }
  264. else
  265. {
  266. ?>
  267. <td><br><input type="reset" value="<?if($lang=='french')echo 'Annuler'; else if($lang=='dutch')echo 'Alles wissen'; else echo ' Reset' ;?>">&nbsp;<input type="submit" name="Next" value="<?if($lang=='french')echo 'Suivant'; else if($lang=='dutch')echo 'Volgende'; else echo 'Next' ;?>"></td>
  268. <?php
  269. }
  270. ?>
  271. </tr></form>
  272. </table>
  273. </td>
  274. <td>&nbsp;</td>
  275. </tr>
  276. <tr>
  277. <td>&nbsp;</td>
  278. <td>&nbsp;</td>
  279. <td>&nbsp;</td>
  280. </tr>
  281. </table>
  282. <?php
  283. /*
  284. ==============================================================================
  285. FOOTER
  286. ==============================================================================
  287. */
  288. Display::display_footer();
  289. ?>