bugfinder Posted May 11, 2009 Share Posted May 11, 2009 Hi All, this is driving nuts out of me ... can some one check this for me..??? 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 I attached the code for u guys to make it easy 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='remove'; 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='remove'; 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..!!! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/157685-issue-with-the-array/ Share on other sites More sharing options...
Ken2k7 Posted May 11, 2009 Share Posted May 11, 2009 Click Forum DOs link in my sig and read #4 on the list. For your array_search function on line 36, swap your parameters so $_SESSION['roomList'] goes before $allocatedTerminals[$i]. I assume $allocatedTerminals[$i] is an array. Link to comment https://forums.phpfreaks.com/topic/157685-issue-with-the-array/#findComment-831792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.