Changeset 5227

Show
Ignore:
Timestamp:
11/07/07 22:20:17 (6 years ago)
Author:
p_lindheimer
Message:

fix case where additional devices were being assigned to a users and the previous assignments were getting lost

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.3/core/functions.inc.php

    r5225 r5227  
    770770    } 
    771771  } 
    772   //if (empty($dial) && strtolower($tech) == "zap") 
    773   //  $dial = "ZAP/".($_REQUEST['channel'] != '' ? $_REQUEST['channel'] : $_REQUEST['devinfo_channel']); 
    774   //if (empty($dial)) 
    775   //  $dial = strtoupper($tech)."/".$id; 
    776772   
    777773  //check to see if we are requesting a new user 
     
    809805    $astman->database_put("DEVICE",$id."/type",$devicetype); 
    810806    $astman->database_put("DEVICE",$id."/default_user",$user); 
    811     if(!empty($emergency_cid)) 
     807    if(!empty($emergency_cid)) { 
    812808      $astman->database_put("DEVICE",$id."/emergency_cid","\"".$emergency_cid."\""); 
    813     if($user != "none") { 
     809    } 
     810 
     811    if ($user != "none") { 
    814812      $existingdevices = $astman->database_get("AMPUSER",$user."/device"); 
    815813      if (empty($existingdevices)) { 
    816814        $astman->database_put("AMPUSER",$user."/device",$id); 
    817815      } else { 
    818         $existingdevices .= "&"; 
    819         //only append device value if this id doesn't exist in it already 
    820         if(strpos($existingdevices,$id."&") === false) // if not containing $id  
    821           $astman->database_put("AMPUSER",$user."/device",$existingdevices.$id); 
    822       } 
    823     } 
     816        $existingdevices_array = explode('&',$existingdevices); 
     817        if (!in_array($id, $existingdevices_array)) { 
     818          $existingdevices_array[]=$id; 
     819          $existingdevices = implode('&',$existingdevices_array); 
     820          $astman->database_put("AMPUSER",$user."/device",$existingdevices); 
     821        } 
     822      } 
     823    } 
     824 
    824825  } else { 
    825826    fatal("Cannot connect to Asterisk Manager with ".$amp_conf["AMPMGRUSER"]."/".$amp_conf["AMPMGRPASS"]); 
     
    871872      // Remove the device record from the user's device list 
    872873      $userdevices = $astman->database_get("AMPUSER",$deviceuser."/device"); 
    873       /*$userdevices = str_replace($account."&", "", $userdevices."&"); 
    874        
    875       // If there was more than one device, remove the extra "&" at the end. 
    876       if (substr($userdevices, -1, 1) == "&") { 
    877         $userdevices = substr($userdevices, 0, -1); 
    878       }*/ 
     874 
     875      // We need to remove just this user and leave the rest alone 
    879876      $userdevicesarr = explode("&", $userdevices); 
    880       array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1); 
     877      $userdevicesarr_hash = array_flip($userdevicesarr); 
     878      unset($userdevicesarr_hash[$account]); 
     879      $userdevicesarr = array_flip($userdevicesarr_hash); 
    881880      $userdevices = implode("&", $userdevicesarr); 
    882881       
     
    21232122 
    21242123 
     2124  //TODO: This needs to be yanked, should be in the upgrade script somewhere not here 
     2125  // 
    21252126  if (count($results) == 0) { 
    21262127    // see if they're still using the old dialprefix method