function saveVoicemail($arrProp)
 {
     $exitoVM = true;
     $pVM = new paloVoicemail($this->_DB);
     $existVM = $pVM->existVoicemail($arrProp['exten'], $arrProp['domain']);
     if ($arrProp['create_vm'] == "yes") {
         if ($existVM == false) {
             $arrVoicemail["context"] = "default";
         }
         $arrVoicemail['organization_domain'] = $arrProp['domain'];
         $arrVoicemail['mailbox'] = $arrProp['exten'];
         $arrVoicemail["password"] = isset($arrProp["vmpassword"]) ? $arrProp["vmpassword"] : null;
         $arrVoicemail["email"] = isset($arrProp["vmemail"]) ? $arrProp["vmemail"] : null;
         $arrVoicemail["attach"] = isset($arrProp["vmattach"]) ? $arrProp["vmattach"] : null;
         $arrVoicemail["saycid"] = isset($arrProp["vmsaycid"]) ? $arrProp["vmsaycid"] : null;
         $arrVoicemail["envelope"] = isset($arrProp["vmenvelope"]) ? $arrProp["vmenvelope"] : null;
         $arrVoicemail["deletevoicemail"] = isset($arrProp["vmdelete"]) ? $arrProp["vmdelete"] : null;
         $arrVoicemail["language"] = isset($arrProp["language"]) ? $arrProp["language"] : null;
         if ($existVM) {
             $exitoVM = $pVM->updateParameters($arrVoicemail);
         } else {
             $pVM->setVoicemailProp($arrVoicemail, $arrProp['domain']);
             $exitoVM = $pVM->createVoicemail();
         }
     } else {
         if ($existVM) {
             $exitoVM = $pVM->deletefromDB($arrProp['exten'], $arrProp['domain']);
         }
     }
     if (!$exitoVM) {
         $this->errMsg = _tr("Error setting voicemail parameters") . $pVM->errMsg;
         return false;
     }
     return true;
 }
 function editDevice($arrProp)
 {
     //validamos que la instacia del objeto haya sido creada correctamente
     if (!$this->validatePaloDevice()) {
         return false;
     }
     $result = $this->getExtension($arrProp["exten"]);
     if ($result != false) {
         $arrProp['device'] = $result['device'];
         $tech = $result['tech'];
         $idExten = $result['id'];
         if ($tech == "iax2") {
             $this->tecnologia = new paloIax($this->tecnologia->_DB);
         } elseif ($tech == "sip") {
             $this->tecnologia = new paloSip($this->tecnologia->_DB);
         } else {
             $this->errMsg = _tr("Invalid Technology");
             return false;
         }
         //si ingreso un nuevo secret lo actualizamos
         $secret = '';
         if (isset($arrProp['secret']) && $arrProp['secret'] != "") {
             if ($tech == "sip") {
                 $secret = $arrProp['secret'];
                 //guardamos el valor sin encriptar
             }
         }
         $arrProp['organization_domain'] = $this->domain;
         if (isset($arrProp['fullname'])) {
             if (!preg_match("/^[[:alnum:]_[:space:]-]+\$/", $arrProp["fullname"])) {
                 $arrProp['fullname'] = $arrProp['exten'];
             }
         } else {
             $arrProp['fullname'] = $arrProp['exten'];
         }
         if (isset($arrProp['clid_number'])) {
             if (!preg_match("/^[[:alnum:]_[:space:]-]+\$/", $arrProp["clid_number"])) {
                 $arrProp['clid_number'] = $arrProp['exten'];
             }
         } else {
             $arrProp['clid_number'] = $arrProp['exten'];
         }
         //verificar si existe un voicemail para la extension
         // 1- Si existe y $arrProp['create_vm']=="yes" => editarlo
         // 2- Si existe y $arrProp['create_vm']=="no" => borrarlo
         // 3- Si no existe y $arrProp['create_vm']=="yes" => crearlo
         $exitoVM = true;
         $pVM = new paloVoicemail($this->tecnologia->_DB);
         $existVM = $pVM->existVoicemail($arrProp['exten'], $this->domain);
         if ($arrProp['create_vm'] == "yes") {
             $arrVoicemail['organization_domain'] = $this->domain;
             $arrVoicemail["context"] = isset($arrProp["vmcontext"]) ? $arrProp["vmcontext"] : null;
             $arrVoicemail["mailbox"] = isset($arrProp['exten']) ? $arrProp["exten"] : null;
             $arrVoicemail["password"] = isset($arrProp["vmpassword"]) ? $arrProp["vmpassword"] : null;
             $arrVoicemail["email"] = isset($arrProp["vmemail"]) ? $arrProp["vmemail"] : null;
             $arrVoicemail["attach"] = isset($arrProp["vmattach"]) ? $arrProp["vmattach"] : null;
             $arrVoicemail["saycid"] = isset($arrProp["vmsaycid"]) ? $arrProp["vmsaycid"] : null;
             $arrVoicemail["envelope"] = isset($arrProp["vmenvelope"]) ? $arrProp["vmenvelope"] : null;
             $arrVoicemail["deletevoicemail"] = isset($arrProp["vmdelete"]) ? $arrProp["vmdelete"] : null;
             $arrVoicemail["fullname"] = isset($arrProp["fullname"]) ? $arrProp["fullname"] : $arrProp['exten'];
             $arrVoicemail["language"] = isset($arrProp["language"]) ? $arrProp["language"] : null;
             //leer las caractirsiticas que el usuario puede poner en vmoptions, estas deben estar separadas por un " | "
             if (isset($arrProp['vmoptions'])) {
                 $arrTemp = explode("|", $arrProp['vmoptions']);
                 foreach ($arrTemp as $value) {
                     $arrVmOpt = explode("=", $value);
                     if (count($arrVmOpt) == 2) {
                         $arrVoicemail[$arrVmOpt[0]] = $arrVmOpt[1];
                     }
                 }
             }
             if ($existVM) {
                 $exitoVM = $pVM->updateParameters($arrVoicemail);
             } else {
                 $pVM->setVoicemailProp($arrVoicemail, $this->domain);
                 $exitoVM = $pVM->createVoicemail();
             }
         } else {
             if ($existVM) {
                 $exitoVM = $pVM->deletefromDB($arrProp['exten'], $this->domain);
             }
         }
         if (!$exitoVM) {
             $this->errMsg = _tr("Error setting voicemail parameters") . $pVM->errMsg;
             return false;
         }
         if ($arrProp['create_vm'] == "yes") {
             $arrProp['mailbox'] = $arrProp['exten'] . "@" . $this->code . "-" . $arrVoicemail["context"];
             $arrProp["voicemail_context"] = $this->code . "-" . $arrVoicemail["context"];
         } else {
             $arrProp["voicemail_context"] = "novm";
         }
         //actualizamos el dispositivo
         $arrProp['name'] = $arrProp['device'];
         if ($this->tecnologia->updateParameters($arrProp) == false) {
             $this->errMsg = "Error setting parameter {$tech} device " . $this->tecnologia->errMsg;
             return false;
         }
         //guardar los setting en la tabla extensions; para despues con esta informacion procede a crear las extensiones de tipo local en el plan de marcado
         if (isset($arrProp['rt'])) {
             if (!preg_match("/^[[:digit:]]+\$/", $arrProp['rt']) && !($arrProp['rt'] > 0 && $arrProp['rt'] < 60)) {
                 $arrProp['rt'] = 0;
             } else {
                 $arrProp['rt'] = $arrProp['rt'];
             }
         } else {
             $arrProp['rt'] = 0;
         }
         // Validamos los recording
         foreach (array('record_in', 'record_out') as $k) {
             if (!in_array($arrProp[$k], array('always', 'never', 'on_demand'))) {
                 $arrProp[$k] = 'on_demand';
             }
         }
         //si la cuenta sip tiene dispositivo elxweb_device entonces se lo agrega
         if ($tech == 'sip') {
             //si la cuenta sip tiene dispositivo elxweb_device entonces debe ser actualizado
             if (isset($arrProp["elxweb_device"])) {
                 if (!empty($arrProp["elxweb_device"])) {
                     $IM = $arrProp;
                     $IM['name'] = $arrProp["elxweb_device"];
                     $IM['secret'] = $secret;
                     $IM["outofcall_message_context"] = 'im-sip';
                     $IM["subscribecontext"] = 'im-sip';
                     $IM['id_exten'] = $idExten;
                     //este campo es para indicar que la cuenta sip usada
                     //para IM esta relacionada con la extension
                     $IM['display_name'] = $arrProp['fullname'];
                     $IM['update_device'] = true;
                     $pIM = new paloIM($this->tecnologia->_DB, $this->domain);
                     if (!$pIM->updateIMAccount($IM)) {
                         $this->errMsg = _tr("An error as ocurred to set IM account. ") . $pIM->errMsg;
                         return false;
                     }
                     $arrProp["enable_chat"] = 'yes';
                 } else {
                     $arrProp["enable_chat"] = 'no';
                 }
             } else {
                 $arrProp["elxweb_device"] = NULL;
                 $arrProp["enable_chat"] = 'no';
             }
         } else {
             $arrProp["elxweb_device"] = NULL;
             $arrProp["enable_chat"] = 'no';
         }
         $arrExten['tech'] = $tech;
         $arrExten['dial'] = $arrProp['dial'];
         $arrExten['exten'] = $arrProp['exten'];
         $arrExten['clid_number'] = $arrProp['clid_number'];
         $arrExten['clid_name'] = $arrProp['fullname'];
         $arrExten['device'] = $arrProp['device'];
         $arrExten['rt'] = $arrProp['rt'];
         $arrExten['record_in'] = $arrProp['record_in'];
         $arrExten['record_out'] = $arrProp['record_out'];
         $arrExten['context'] = $arrProp['context'];
         $arrExten['voicemail'] = $arrProp["voicemail_context"];
         $arrExten['outboundcid'] = isset($arrProp['out_clid']) ? $arrProp['out_clid'] : "";
         $arrExten['alias'] = isset($arrProp['alias']) ? $arrProp['alias'] : "";
         $arrExten['mohclass'] = '';
         $arrExten['noanswer'] = '';
         $arrExten['elxweb_device'] = isset($arrProp["elxweb_device"]) ? $arrProp["elxweb_device"] : NULL;
         $arrExten['enable_chat'] = isset($arrProp["enable_chat"]) ? $arrProp["enable_chat"] : 'no';
         $exito = $this->editExtensionDB($arrExten);
         if ($exito) {
             if ($this->insertDeviceASTDB($arrProp)) {
                 return true;
             } else {
                 $this->errMsg = "Extension couldn't be updated ." . $this->errMsg;
                 return false;
             }
         } else {
             $this->errMsg = "Problem when trying updated data in extensions table. " . $this->errMsg;
             return false;
         }
     } else {
         return false;
     }
 }