/** * Function to save record * @param <Vtiger_Request> $request - values of the record * @return <RecordModel> - record Model of saved record */ public function saveRecord($request) { $recordId = $request->get('record'); $recordModel = $this->getRecordModelFromRequest($request); $mode = $recordModel->get('mode'); $adb = PearDatabase::getInstance(); // check if encryption is enabled $config == false; if (file_exists('modules/OSSPasswords/config.ini.php')) { $config = parse_ini_file('modules/OSSPasswords/config.ini.php'); } //check if password was edited with hidden password $properPassword = $recordModel->get('password'); // edit mode if ($recordId != '' && $mode == 'edit') { if ($properPassword == '**********') { // hidden password sent in edit mode, get the correct one if ($config) { // when encryption is on $sql = "SELECT AES_DECRYPT(`password`, '" . $config['key'] . "') AS pass FROM `vtiger_osspasswords` WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($recordId), true); $properPassword = $adb->query_result($result, 0, 'pass'); } else { // encryption mode is off $sql = "SELECT `password` AS pass FROM `vtiger_osspasswords` WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($recordId), true); $properPassword = $adb->query_result($result, 0, 'pass'); } } $recordModel->set('password', $properPassword); $recordModel->save(); // after save we check if encryption is active if ($config) { $sql = "UPDATE `vtiger_osspasswords` SET `password` = AES_ENCRYPT(?,?) WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($properPassword, $config['key'], $recordId), true); } } else { if ($recordId == '' && $mode == '') { $recordModel->save(); // if encryption mode is on we will encrypt the password $recordId = $recordModel->get('id'); if ($config) { // when encryption is on $sql = "UPDATE `vtiger_osspasswords` SET `password` = AES_ENCRYPT(`password`, ?) WHERE `osspasswordsid` = ?;"; $result = $adb->pquery($sql, array($config['key'], $recordId), true); } } } if ($request->get('relationOperation')) { $parentModuleName = $request->get('sourceModule'); $parentModuleModel = Vtiger_Module_Model::getInstance($parentModuleName); $parentRecordId = $request->get('sourceRecord'); $relatedModule = $recordModel->getModule(); $relatedRecordId = $recordModel->getId(); $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule); $relationModel->addRelation($parentRecordId, $relatedRecordId); } return $recordModel; }
/** * Function to respond for incoming calls * @param <Vtiger_Request> $details */ public function respondToIncomingCall($details) { $current_user = vglobal('current_user'); self::$NUMBERS = PBXManager_Record_Model::getUserNumbers(); header("Content-type: text/xml; charset=utf-8"); $response = '<?xml version="1.0" encoding="utf-8"?>'; $response .= '<Response><Dial><Authentication>'; $response .= 'Success</Authentication>'; if (self::$NUMBERS) { foreach (self::$NUMBERS as $userId => $number) { $userInstance = Users_Privileges_Model::getInstanceById($userId); $current_user = $userInstance; $callPermission = Users_Privileges_Model::isPermitted('PBXManager', 'ReceiveIncomingCalls'); if ($number != $details->get('callerIdNumber') && $callPermission) { if (preg_match("/sip/", $number) || preg_match("/@/", $number)) { $number = trim($number, "/sip:/"); $response .= '<Number>SIP/'; $response .= $number; $response .= '</Number>'; } else { $response .= '<Number>SIP/'; $response .= $number; $response .= '</Number>'; } } } } else { $response .= '<ConfiguredNumber>empty</ConfiguredNumber>'; $date = date('Y/m/d H:i:s'); $params['callstatus'] = 'no-answer'; $params['starttime'] = $date; $params['endtime'] = $date; $recordModel = PBXManager_Record_Model::getInstanceBySourceUUID($details->get('callUUID')); $recordModel->updateCallDetails($params); } $response .= '</Dial></Response>'; echo $response; }