Upgrade to my premade reply mod
This upgrade does not do exactly what I want. I would prefer to do this using the AJAX class used to bring in the premade replied but i cannot figure out how. If anyone knows please let me know.
Secondly if I cant use the AJAX class can someone tell me how to remove the ID from the select box? Its showing up in the select box like pictured below.
NOTE: THIS IS AN UPGRADE FROM MY ORIGINAL MOD. YOU WILL WANT TO COPY MY ORIGINAL MOD FIRST AND THEN MAKE CHANGES AS MENTIONED BELOW.
Onto the code. Hope I do this right.
REPLACE:
<?
$sql='(SELECT premade_id,title FROM '.KB_PREMADE_TABLE.' WHERE isenabled=1)';
$canned=db_query($sql);
if($canned && db_num_rows($canned)) {
?>
<select id="canned" name="canned"
onChange="getCannedResponse(this.options.value,this.form);this.selectedIndex='0';" >
<option value="0" selected="selected">Select a premade reply</option>
<?while(list($cannedId,$title)=db_fetch_row($canned)) { ?>
<option value="<?=$cannedId?>" ><?=Format:($title)?></option>
<?}?>
</select> <input type='checkbox' value='1' name=append checked="true" />Append
<?}?>
WITH:
<select id="canned" name="canned" onChange="getCannedResponse(this.options.value,this.form);this.selectedIndex='0';" >
<option value="0" selected="selected">Select a premade reply</option>
</select> <input type='checkbox' value='1' name=append checked="true" />Append
FIND:
<?php
if(!defined('OSTSCPINC') || !is_object($thisuser) || !$thisuser->isStaff()) die('Access Denied');
$info=($_POST && $errors)?Format:($_POST)(); //on error...use the post data
?>
DIRECTLY BELOW THE ABOVE MENTIONED CODE ADD:
<script language='javascript'>
var canned = new Array();
<?
$departments= db_query('SELECT dept_id,dept_name FROM '.DEPT_TABLE.' ORDER BY dept_name');
while (list($deptId,$dept) = db_fetch_row($departments)){; ?>
<?
$sql='(SELECT premade_id,title FROM '.KB_PREMADE_TABLE.' WHERE isenabled=1 and dept_id = '.$deptId.')';
$canned_dept=db_query($sql);
?>
canned = ",<? while (list($cannedId,$title) = db_fetch_row($canned_dept)){; ?><?=$cannedId?>;<?=$title?>,<? } ?>";
<? }?>
function loadOptions(sParentBox, sChildBox)
{
//get the value of the selected option
var sParentValue = document.getElementById(sParentBox).value;
//alert(sParentValue);
//load the appropriate event list to the option box
var theSel = document.getElementById(sChildBox);
//clear previous options
theSel.options.length = null;
//handle if there is no value
if (sParentValue == ''){alert("exiting"); return;}
if (sParentBox == "deptId") {
oTargetArray = canned;
}
//split the array values by the separator
var arrList = oTargetArray.split(",");
//loop thru the array of options to add them to the dropdown
for (x=0; x < arrList.length; x++)
{
var newOpt = new Option(arrList, arrList);//(theText,theValue);
var selLength = theSel.length;
theSel.options = newOpt;
}//next
}//end func
</script>