<?php
include_once('../../../inc/claro_init_global.inc.php');
?>

<html>

<head>
  <title>Insert Math / LaTeX</title>

<script type="text/javascript" src="popup.js"></script>

<script type="text/javascript">

window.resizeTo(400, 100);

I18N = window.opener.HTMLArea.I18N.dialogs;

function i18n(str) {
  return (I18N[str] || str);
};

function Init() {
  __dlg_translate(I18N);
  __dlg_init();
  var param = window.dialogArguments;
  if (param) {
      document.getElementById("f_vert").value = param["f_vert"];
      document.getElementById("f_horiz").value = param["f_horiz"];
  }

  document.formConfig.wiki.focus();
};

function onOK() {
  var required = {
    "f_wiki": "You must select a wiki link"
  };
  for (var i in required) {
    var el = document.getElementById(i);
    if (!el.value) {
      alert(required[i]);
      el.focus();
      return false;
    }
  }
  // pass data back to the calling window
  // var fields = ["f_horiz", "f_vert", "f_latex", "f_autosize"];
  var fields = ["f_wiki"];
  var param = new Object();
  for (var i in fields) {
    var id = fields[i];
    var el = document.getElementById(id);
    param[id] = el.value;
  }
  __dlg_close(param);
  return false;
};

function onCancel() {
  __dlg_close(null);
  return false;
};
</script>

<style type="text/css">
html, body {
  background: ButtonFace;
  color: ButtonText;
  font: 11px Tahoma,Verdana,sans-serif;
  margin: 0px;
  padding: 0px;
}
body { padding: 5px; }
table {
  font: 11px Tahoma,Verdana,sans-serif;
}
form p {
  margin-top: 5px;
  margin-bottom: 5px;
}
.fl { width: 5em; float: left; padding: 2px 5px; text-align: right; }
.fr { float: left; padding: 2px 5px; text-align: right; }
fieldset { padding: 0px 10px 5px 5px; }
select, input, button { font: 11px Tahoma,Verdana,sans-serif; }
button { width: 70px; }
.space { padding: 2px; }

.title { background: #ddf; color: #000; font-weight: bold; font-size: 120%; padding: 3px 10px; margin-bottom: 10px;
border-bottom: 1px solid black; letter-spacing: 2px;
}
form { padding: 0px; margin: 0px; }
</style>

</head>

<body onload="Init()">

<div class="title">Insert WIKI link</div>

<form name="formConfig" action="" method="get">
<p />

<br clear="all" />
<table width="100%" style="margin-bottom: 0.2em">
 <tr>
  <td valign="bottom">
    <span>Select the wiki page: </span>:<br />
	<?php
	// variable definitions
	$CourseWikiPages='Course Wiki Pages';
	$GroupWikiPages='Group wiki pages';
	// Database definition
	$tbl_wiki = "`".$_course['dbNameGlu']."wiki`";

	// The main wiki pages
	$sql='SELECT * FROM '.$tbl_wiki.' WHERE group_id IS NULL GROUP BY reflink ORDER BY reflink ASC';
	$result=api_sql_query($sql,__LINE__,__FILE__);
	echo '<select name="wiki" id="f_wiki">';
	echo '<optgroup label="'.$CourseWikiPages.'">';
	while ($row=mysql_fetch_array($result))
	{
		$userinfo=Database::get_user_info_from_id($row['user_id']);
		echo '<option value="'.$row['reflink'].'">'.$row['title'].'</option>';
		//print_r($userinfo);
	}
	echo '<optgroup>';
	
	// getting the group wiki pages
	include_once (api_get_library_path()."/groupmanager.lib.php");
	$subscribedgroups= GroupManager :: get_group_ids('',$_uid);
	foreach ($subscribedgroups as $group)
	{
		$group_properties=GroupManager :: get_group_properties($group);
		$sql='SELECT * FROM '.$tbl_wiki.' WHERE group_id="'.$group.'" GROUP BY reflink ORDER BY reflink ASC';
		$result=api_sql_query($sql,__LINE__,__FILE__);
		echo '<optgroup label="'.$GroupWikiPages.':'.$group_properties['name'].'">';
		while ($row=mysql_fetch_array($result))
		{
			echo '<option value="'.$row['reflink'].'">'.$row['title'].'</option>';
		}
		echo '<optgroup>';
	}
	echo '</select>';	
?>
  </td>
  <td valign="bottom" style="text-align: right">
  </td>
 </tr>
 <tr>
  <td valign="bottom">
  </td>
  <td valign="bottom" style="text-align: right">
    <button type="button" name="ok" onclick="return onOK();">OK</button><br>
    <button type="button" name="cancel" onclick="return onCancel();">Cancel</button>
  </td>
 </tr>
</table>
</form>
</body>
</html>
