PDA

View Full Version : Issue with the array


bugfinder
05-11-2009, 03:02 PM
Hi All, this is driving nuts out of me ... can some one check this for me..http://www.phpfreaks.com/forums/Smileys/default/huh.gif
Seems i have issue with the array but couldn't make it work ....the Concept of my code is to send emergency to selected room number vise-vase to all rooms

error:- Warning: array_search() [function.array-search]: Wrong datatype for second argument in C:\wamp\www\admin\admin_issue_emergency.php on line 36

here is the code :-

<?PHP
include('checkpoweredusersession.php');
include('config.php');
include('connect.php');
include('getmodules.php');

if (strpos($HTTP_REFERER,'admin_issue_emergency.php') == FALSE)
{
//$_SESSION['roomList'] = NULL;
$selfCall = 1;
}
else
$selfCall = 0;

global $roomList;
//$roomList = array();
if ($action =='add')
{
$count = count ($target_list);
for ($i =0; $i<$count ; $i++)
{
$roomList[] = $target_list[$i];
$allocatedTerminals[] = $target_list[$i];
}

$_SESSION['roomList'] = $roomList;
if ($_SESSION['roomList'])
$_SESSION['roomList'] = array_unique($_SESSION['roomList']);
print_r($_SESSION['roomList']); // to check the array value
}
if ($action =='remove')
{
$count = count ($allocatedTerminals);
for ($i =0; $i<$count ; $i++)
{
$key = array_search($allocatedTerminals[$i], $_SESSION['roomList']);
unSet($_SESSION['roomList'][$key]);
$_SESSION['roomList'][$key] = '';
$key = 0;
}

$_SESSION['roomList'] = array_trim($_SESSION['roomList']);
//print_r($_SESSION['roomList']); /*to check the array value*/
}
$roomList = $_SESSION['roomList'];

$action =send;
if ($btnSend ==$action)
{
$pause = 5;
$sqlMsg = "SELECT * `".$DBTablesPrefix."_emergency_type`";
$Infos = mysql_query($sqlMsg) or die("Query Failed 55");
$j = 0;
while($Row_Infos = mysql_fetch_assoc($Infos))
{
$j++;
$Id =$Row_Infos["Id"];
$msg =$Row_Infos["name"];
if ($Id == $name)
{
$display_message = $msg;
}
}
$commandURL = "../emergency/simple_remote_control.php4?message=".urlencode(stripslashes($display_message));
$cmdOptions = "/PASSWORD \"".$aminoRemoteControlPassPhrase."\" /TIMEOUT 12 /THREADS 60 /PAUSE ".$pause." /QUIET";

//integration of STBremoteConf
$cmdCommand = "/LOADURL ".$FULL_UNRESTRICTED_PATH."simple_emergency_message.php"."?message=".urlencode(stripslashes($display_message));
//$cmdFile = "/FILE \"".$tIpListFiles[$TERM_TYPE_AMINET100][0]."\"";
if ($target_type == 'all')
{
$sqlTerminals ="SELECT IP, Room FROM `".$DBTablesPrefix."_stbs` "." WHERE Version='aminet110' "." ORDER BY (Room+0)";
$Infos = mysql_query($sqlTerminals) or die("Query Failed 76");
$i= 0;
while($Row_Infos = mysql_fetch_assoc($Infos))
{
$i++;
$termIP = $Row_Infos ["IP"];
$termRoom = $Row_Infos ["Room"];
$cmdLine = "STB_visualacfg.exe ".$cmdCommand." ".$cmdOptions." ".' TERMINALCHANGE '.$termIP;
exec( $cmdLine, $cmdOutput);
}
$termCount = $i;
}
else if ($target_type == 'room')
{

for ($i = 0; $i< count($roomList); $i++)
{
$sqlTerminals = "SELECT IP, Room FROM `".$DBTablesPrefix."_stbs` "." WHERE Room = '$roomList[$i]'";
$Infos = mysql_query($sqlTerminals) or die("Query Failed 94");
while($Row_Infos = mysql_fetch_assoc($Infos))
if ($i > 0)
{
$IP_terminal = $Row_Infos["IP"];

$cmdLine = "STB_visualacfg.exe ".$cmdCommand." ".$cmdOptions." ".' TERMINALCHANGE '.$IP_terminal;
//echo $cmdLine;
exec( $cmdLine, $cmdOutput );
}
}
}
}


if (!isset($target_type))
$target_type = 'all';
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
Base1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-transform: none;
color: #663300;
}
-->
</style>
<script language="javascript">
function disableItems(selectedItem)
{
if (selectedItem.value =='all')
{

document.getElementById("target_list").disabled = true;
document.getElementById("allocatedTerminals").disabled = true;
}

else if (selectedItem.value =='room')
{
document.getElementById("target_list").disabled = false;
document.getElementById("allocatedTerminals").disabled = false;
}

}
window.onload=function()
{
var targetType = '<? echo $target_type;?>';
if (targetType =='all')
{
document.getElementById("target_list").disabled = true;
document.getElementById("allocatedTerminals").disabled = true;
}
else if (targetType =='room')
{
document.getElementById("target_list").disabled = false;
document.getElementById("allocatedTerminals").disabled = false;
}
}
</script>
<link href="hoteltv.css" rel="stylesheet" type="text/css">
</head>
<body background="img/bg.gif">
<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="FFFFFF" >
<tr>
<td>
<?PHP include('head_servicesmanagement.php'); ?>
</td>
</tr>
<tr ><td colspan=""><br>
<?php
echo'<p align="center"><font color="#666666" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>' ;
echo "Issue Emergency";
echo'</strong></font></p>';

?>
</td></tr>
<tr><td><br>
<form method='get' name='form_allocate_terminals'>
<table border="0" cellpadding="1" cellspacing="0" width="50%" align="center" class="tableForm">

<tr>
<td>
<table border="0" cellpadding="4" cellspacing="0" width="100%" align="center">
<tr>
<td align="left" valign="middle" width="3%" ><font size="2"><strong>
Type:</strong></font>
</td>
<td align="left" valign="middle" colspan="3">
<select name="message" >
<?
$sqlMsg = "SELECT * FROM `".$DBTablesPrefix."_emergency_type`";
$Infos = mysql_query($sqlMsg) or die("Query failed on line 156");
$totalRows = mysql_num_rows($Infos);
//$j =0;
for ( $i = 0; $i < $totalRows; $i++ )
while($Row_Infos = mysql_fetch_assoc($Infos))
{
//$j++;
$type_ID = $Row_Infos["Id"];
$message = $Row_Infos["name"];
echo "<option value='".$type_ID."' ".$strSelected.">".$message;
}
?>
</select>
</td>
</tr>
<tr>
<td align="left" valign="middle" width="3%" colspan="4">
<input type="radio" name="target_type" value="all" <?=($target_type=="all")?"checked":""?> onClick="disableItems(this);">
<font size="2"><strong>All:</strong></font> </td>
</tr>

<tr>
<td align="left" valign="middle" width="3%" colspan="4">
<input type="radio" name="target_type" value="room" <?=($target_type=="room")?"checked":""?> onClick="disableItems(this);">
<font size="2"><strong>Rooms:</strong></font></td>
</tr>
<tr>
<td></td>
<td align="left" valign="middle" width="10%">

<select name="target_list[]" id ='target_list' size="3" multiple onChange="/*document.form_allocate_terminals.target_type[0].checked=true*/" >
<?
//terminal identification in multi-terminal rooms
$sqlTerminals ="SELECT IP, Room FROM `".$DBTablesPrefix."_stbs` "." WHERE (Version='aminet110') "." ORDER BY (Room+0)";
$Infos = mysql_query($sqlTerminals) or die("Query failed on line 188");
$termCount = mysql_num_rows($Infos);
for ( $i = 0; $i < $termCount; $i++ )
//$i = 0;
while($Row_Infos = mysql_fetch_assoc($Infos))

{
//$i++;
$termIP = $Row_Infos["IP"];
$termRoom = $Row_Infos["Room"];
$messRoom = Room; //Room

//terminal identification in multi-terminal rooms
if ($roomList)
{
//$key = array_search($termRoom, $roomList); // $key = 2;
$key = in_array($termRoom, $roomList);
}
//echo 'R '. $termRoom . $key." k <br>";
if ($key != true)
echo "<option value='".$termRoom."' ".$strSelected.">$messRoom ".$termRoom." \r\n";

}
?>
</select>

</td>
<td width="10%" class="light" align="center" valign="middle">
<input type="hidden" name="action" value="add">
<table border="0">
<tr align="center" height="50%">
<td width="30%">
<?
echo '<img src="../admin/img/right.gif" border="0"><img src="../admin/img/right.gif" border="0">';
?>
</td>
<td><input type="submit" onClick="document.form_allocate_terminals.action.value='add '; return true;" value="Add"></td>
<td width="30%">
<?
echo '<img src="../admin/img/right.gif" border="0"><img src="../admin/img/right.gif" border="0">';
?>
</td>
</tr>
<tr align="center" height="50%">
<td width="30%">
<?
echo '<img src="../admin/img/left.gif" border="0"><img src="../admin/img/left.gif" border="0">';
?>
</td>
<td><input type="submit" onClick="document.form_allocate_terminals.action.value='rem ove'; return true;" value="Remove"></td>
<td width="30%">
<?
echo '<img src="../admin/img/left.gif" border="0"><img src="../admin/img/left.gif" border="0">';
?>
</td>
</tr>
</table>
</td>
<td width="30%">
<select name="allocatedTerminals[]" id='allocatedTerminals' size="3" multiple onDblClick="document.form_allocate_terminals.action.value='rem ove'; document.form_allocate_terminals.submit();">
<?
$termCount = count($roomList);
for ($i = 0; $i < $termCount; $i++)
{
$termRoom = $roomList[$i];
$messRoom = Room; //ROOM
echo "<option value='".$termRoom."' ".$strSelected.">$messRoom ".$termRoom." \r\n";
}
?>
</select>
</td>
</tr>


<tr>
<td colspan="4" align="center"><input type="submit" name='btnSend' value="Send"></td>
</tr>
</table>
</td>
</tr>
</table>

</form>
<tr><td><?PHP include('tail.php'); ?></td></tr>
</td></tr>
</table>
</body>
</html>
<?
/**
* Trims an array from empty elements.
*
* @param $a the array to trim.
* @return a new array with the empty elements removed.
*/
function array_trim($a)
{
$j = 0;
for ($i = 0; $i < count($a); $i++)
{
if ($a[$i] != "")
{
$b[$j++] = $a[$i];
}
}
return $b;
}
?>


any help will be greatly appreciated..!!!

davidj
05-11-2009, 04:42 PM
the error you posted is just a warning

adjust your error handling in your php.ini

let me know if it still doesn't work

bugfinder
05-12-2009, 06:37 AM
I tried it, it still didn't work. still dont know where im going wrong

bugfinder
05-12-2009, 02:18 PM
hi, can you tell me what exactly i to check with the php.ini..??? i'm stuck here and i really really have finish this

edbr
05-13-2009, 03:03 AM
there is a section name error handling.
heres some info i copied from mine (apache2triad), you may have the same

; - Show all errors, except for notices and coding standards warnings
;
;error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
; - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors except for notices and coding standards warnings
;
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = Off

; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = On

; Log errors into a log file (server-specific log, stderr, or error_log (below))
; As stated above, you're strongly advised to use error logging in place of
; error displaying on production web sites.
log_errors = On

; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
log_errors_max_len = 1024

; Do not log repeated messages. Repeated errors must occur in same file on same
; line until ignore_repeated_source is set true.
ignore_repeated_errors = On

; Ignore source of message when ignoring repeated messages. When this setting
; is On you will not log errors with repeated messages from different files or
; sourcelines.
ignore_repeated_source = Off

; If this parameter is set to Off, then memory leaks will not be shown (on
; stdout or in the log). This has only effect in a debug compile, and if
; error reporting includes E_WARNING in the allowed list
report_memleaks = On

; Store the last error/warning message in $php_errormsg (boolean).
track_errors = On

; Disable the inclusion of HTML tags in error messages.
; Note: Never use this feature for production boxes.
html_errors = Off
etc,etc

bugfinder
05-13-2009, 09:22 AM
thanks for reply... i checked with my php.ini file and did the change like your. but still i have issue with it , it only stopped showing the warning but its not doing what it suppose to do . when i try to add room number from target_list to allocatedlist its only adding one room and if i try to add another its replacing with the other but not adding with the pervious room ....what do u suggest me in this case ....